how to find the "Xpath for a checkbox in Nth Row ... "

611 views
Skip to first unread message

Varun Mukka

unread,
Feb 16, 2012, 7:01:09 AM2/16/12
to Selenium Users
Hi some one please help me find out the XPath for the checkbox in the
Nth Row ...
For Example tell me the Xpath for the checkbox in 4th row in this HTML
code

<tr class="em-table-row em-table-row-odd">
<td class="em-table-cell0 em-table-cell-even em-table-col0 em-multi-
select-checkbox-cell">
<input class="gwt-SimpleCheckBox em-table-cell-widget" type="checkbox"
tabindex="0">
</td>
<td class="em-table-cell em-table-cell-odd em-table-col1">
<td class="em-table-cell em-table-cell-even em-table-col2">
<td class="em-table-cell em-table-cell-odd em-table-col3">
<td class="em-table-cell em-table-cell-even em-table-col4">
<td class="em-table-cell em-table-cell-odd em-table-col5">
<td class="em-table-cell em-table-cell-even em-table-col6">
</tr>
<tr class="em-table-row em-table-row-even">
<td class="em-table-cell0 em-table-cell-even em-table-col0 em-multi-
select-checkbox-cell">
<input class="gwt-SimpleCheckBox em-table-cell-widget" type="checkbox"
tabindex="0">
</td>
<td class="em-table-cell em-table-cell-odd em-table-col1">
<td class="em-table-cell em-table-cell-even em-table-col2">
<td class="em-table-cell em-table-cell-odd em-table-col3">
<td class="em-table-cell em-table-cell-even em-table-col4">
<td class="em-table-cell em-table-cell-odd em-table-col5">
<td class="em-table-cell em-table-cell-even em-table-col6">
</tr>
<tr class="em-table-row em-table-row-odd">
<td class="em-table-cell0 em-table-cell-even em-table-col0 em-multi-
select-checkbox-cell">
<input class="gwt-SimpleCheckBox em-table-cell-widget" type="checkbox"
tabindex="0">
</td>
<td class="em-table-cell em-table-cell-odd em-table-col1">
<td class="em-table-cell em-table-cell-even em-table-col2">
<td class="em-table-cell em-table-cell-odd em-table-col3">
<td class="em-table-cell em-table-cell-even em-table-col4">
<td class="em-table-cell em-table-cell-odd em-table-col5">
<td class="em-table-cell em-table-cell-even em-table-col6">
</tr>
<tr class="em-table-row em-table-row-even">
<td class="em-table-cell0 em-table-cell-even em-table-col0 em-multi-
select-checkbox-cell">
<input class="gwt-SimpleCheckBox em-table-cell-widget" type="checkbox"
tabindex="0" checked="">
</td>

Lutfi Dughman

unread,
Feb 16, 2012, 12:05:51 PM2/16/12
to seleniu...@googlegroups.com
simplest is 

//TR[4]//INPUT     or //TABLE[@id='some id']/TBODY/TR[4]//INPUT


but this is not wholly correct, i would suggest looking at the row and see what unique text does it's cells have, then you can reference the parent and the checkbox at the same time, like this:

//TD[.='unique text']/..//INPUT


what this does it find a TD that contains text 'unique text' then '/../' notation points to the parent node (which is the TR), then '//' notation will find any input field that is descendent of that TR.


there are other ways to do it, different needs different ways, but this should be a good start


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Varun Mukka

unread,
Feb 16, 2012, 1:30:27 PM2/16/12
to seleniu...@googlegroups.com
Thanks Lutfi. Appreciate your immediate response.
I will try this today and update you if I need anything.

Thanks,
Varun

Kenneth Koontz

unread,
Feb 16, 2012, 3:57:24 PM2/16/12
to Selenium Users
Lufti,

I know this is out of the context of this thread, but why do you say
that '//tr[4]//input' is 'not wholly correct'?

On Feb 16, 9:05 am, Lutfi Dughman <lutf...@gmail.com> wrote:
> simplest is
>
> //TR[4]//INPUT     or //TABLE[@id='some id']/TBODY/TR[4]//INPUT
>
> but this is not wholly correct, i would suggest looking at the row and see
> what unique text does it's cells have, then you can reference the parent
> and the checkbox at the same time, like this:
>
> //TD[.='unique text']/..//INPUT
>
> what this does it find a TD that contains text 'unique text' then '/../'
> notation points to the parent node (which is the TR), then '//' notation
> will find any input field that is descendent of that TR.
>
> there are other ways to do it, different needs different ways, but this
> should be a good start
>

Varun Mukka

unread,
Feb 16, 2012, 4:06:36 PM2/16/12
to seleniu...@googlegroups.com
Hi Lufti,

Its working like crazy ... thanks for the help ...
As u suggested   //TD[.='unique text']/..//INPUT is the perfect and generalized one which works in all the cases for me.
Because my table changes dynamically, the unique text part helps me a lot.

Thanks,
Varun 
Reply all
Reply to author
Forward
0 new messages