XPath for exact text match

2,764 views
Skip to first unread message

parikshit chakraborty

unread,
Jun 5, 2013, 1:33:44 AM6/5/13
to webd...@googlegroups.com
Hello All,

I have an HTML as below where I need to find out Radio Button for an item "SM_ONBOARD_SERVICE". When I filter using SM_ONBOARD_SERVICE, I get two item rows in the table viz. SM_ONBOARD_SERVICE & SM_ONBOARD_SERVICE_PLAN.

 The XPath I am using to check the radio button pertaining to SM_ONBOARD_SERVICE is as below:

                                        //td[./text()='SM_ONBOARD_SERVICE']/preceding-sibling::td/div

Above XPath works absolutely fine when I try it using XPath checker or FirePath and is returning me only one match. But when I execute the script it fails saying that the element is not visible.

I cannot use  //td[contains(text(),'SM_ONBOARD_SERVICE')]/preceding-sibling::td/div  as it returns 2 matches always, radio buttons for both SM_ONBOARD_SERVICE & SM_ONBOARD_SERVICE_PLAN

HTMLSnippet:

<div class="dojoxGridRow" role="row" aria-selected="false" style="">
<table class="dojoxGridRowTable" cellspacing="0" cellpadding="0" border="0" role="presentation" style="width: 503px;">
<tbody>
<tr>
<td class="dojoxGridCell " style="text-align: center;width:30px;" idx="0" role="gridcell" tabindex="-1">
<div id="dojox_grid_EnhancedGrid_1_rowSelector_0" class="dojoxGridRowSelector dijitReset dijitInline dijitRadio" aria-label="Row 1, single selection, radio box" aria-disabled="false" aria-                  pressed="false" role="presentation" name="dojox_grid_EnhancedGrid_1_rowSelector" tabindex="-1">
<span class=" dojoxGridRowSelectorStatusText">O</span>
</div>
</td>
<td class="dojoxGridCell " style="display:none;width:5%;" idx="1" role="gridcell" tabindex="-1">...</td>
<td class="dojoxGridCell " style="width:auto;" idx="2" role="gridcell" tabindex="-1">SM_ONBOARD_SERVICE</td>
<td class="dojoxGridCell " style="width:auto;" idx="3" role="gridcell" tabindex="-1"/>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" style="">
<table class="dojoxGridRowTable" cellspacing="0" cellpadding="0" border="0" role="presentation" style="width: 503px;">
<tbody>
<tr>
<td class="dojoxGridCell " style="text-align: center;width:30px;" idx="0" role="gridcell" tabindex="-1">
<div id="dojox_grid_EnhancedGrid_1_rowSelector_1" class="dojoxGridRowSelector dijitReset dijitInline dijitRadio" aria-label="Row 2, single selection, radio box" aria-disabled="false" aria-pressed="false" role="presentation" name="dojox_grid_EnhancedGrid_1_rowSelector" tabindex="-1">
<span class=" dojoxGridRowSelectorStatusText">O</span>
</div>
</td>
<td class="dojoxGridCell " style="display:none;width:5%;" idx="1" role="gridcell" tabindex="-1">...</td>
<td class="dojoxGridCell " style="width:auto;" idx="2" role="gridcell" tabindex="-1">SM_ONBOARD_SERVICE_PLAN</td>
<td class="dojoxGridCell " style="width:auto;" idx="3" role="gridcell" tabindex="-1"/>
</tr>
</tbody>
</table>
</div>

Please help me in getting the exact XPath for  SM_ONBOARD_SERVICE.


Regards,
Parikshit

Mark Collin

unread,
Jun 5, 2013, 4:10:15 AM6/5/13
to webd...@googlegroups.com
Have you tried using an explicit wait?

It sounds like the XPath is fine, but the problem is that the element isn't there when you search for it.
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

darrell

unread,
Jun 5, 2013, 10:34:10 PM6/5/13
to webdriver
Read the error message: the element is not visible.

It has nothing to do with your XPath not finding the element. It finds
the element and it is present BUT it is not visible. For example, if
the code was:

WebElement we = driver.findElement(By.xpath("//
td[text()='SM_ONBOARD_SERVICE']/preceding::td/div"));
System.out.println(we.isDisplayed());

It would print false because the element is not visible. You probably
have to do something to enable the radio button before you can
interact with it. Remember that you are simulating a manual tester. If
I have to enable a checkbox before I can select the radio button then
WebDriver needs to enable the checkbox before it can select the radio
button.



On Jun 5, 1:33 am, parikshit chakraborty <itsmyzones...@gmail.com>
wrote:
> Hello All,
>
> I have an HTML as below where I need to find out Radio Button for an item "*
> SM_ONBOARD_SERVICE*". When I filter using SM_ONBOARD_SERVICE, I get two
> item rows in the table viz. *SM_ONBOARD_SERVICE & **SM_ONBOARD_SERVICE_PLAN.
> *
> *
> *
>  The XPath I am using to check the radio button pertaining to *SM_ONBOARD_SERVICE
> *is as below:
>
> *
> //td[./text()='SM_ONBOARD_SERVICE']/preceding-sibling::td/div*
> *
> *
> Above XPath works absolutely fine when I try it using XPath checker or
> FirePath and is returning me only one match. But when I execute the script
> it fails saying that the element is not visible.
>
> I cannot use * //td[contains(text(),'SM_ONBOARD_SERVICE')]/preceding-sibling::td/div
> * as it returns 2 matches always, radio buttons for both *SM_ONBOARD_SERVICE
> & **SM_ONBOARD_SERVICE_PLAN*
>
> *HTMLSnippet:*
> *
> *
> <div class="dojoxGridRow" role="row" aria-selected="false" style="">
> <table class="dojoxGridRowTable" cellspacing="0" cellpadding="0" border="0"
> role="presentation" style="width: 503px;">
> <tbody>
> <tr>
> <td class="dojoxGridCell " style="text-align: center;width:30px;" idx="0"
> role="gridcell" tabindex="-1">
> <div id="dojox_grid_EnhancedGrid_1_rowSelector_0"
> class="dojoxGridRowSelector dijitReset dijitInline dijitRadio"
> aria-label="Row 1, single selection, radio box" aria-disabled="false" aria-
>                  pressed="false" role="presentation"
> name="dojox_grid_EnhancedGrid_1_rowSelector" tabindex="-1">
> <span class=" dojoxGridRowSelectorStatusText">O</span>
> </div>
> </td>
> <td class="dojoxGridCell " style="display:none;width:5%;" idx="1"
> role="gridcell" tabindex="-1">...</td>
> <td class="dojoxGridCell " style="width:auto;" idx="2" role="gridcell"
> tabindex="-1">*SM_ONBOARD_SERVICE*</td>
> tabindex="-1">*SM_ONBOARD_SERVICE_PLAN*</td>
> <td class="dojoxGridCell " style="width:auto;" idx="3" role="gridcell"
> tabindex="-1"/>
> </tr>
> </tbody>
> </table>
> </div>
>
> Please help me in getting the exact XPath for  *SM_ONBOARD_SERVICE.*
> *
> *
> *
> *
> Regards,
> Parikshit

susanth b

unread,
Jun 17, 2013, 6:56:48 AM6/17/13
to webd...@googlegroups.com

Hi,
 more specific one

 //td[starts-with(text(),'SM_ONBOARD_SERVICE')]/preceding-sibling::td/div [0]

Regards,
Susanth B
Reply all
Reply to author
Forward
0 new messages