locating elements using nextSibling

2,762 views
Skip to first unread message

t_brc

unread,
Mar 14, 2012, 5:10:01 PM3/14/12
to Selenium Users
Hello,

I am trying to find xpath expression to get the text value from the
table cell,

HTML code
*************
<tr>
<td class="label-column">
<img title="Required" alt="Required" style="width: 12px; height:
9px;" src="ui/uitk/images/s.gif">
<img title="Enter Once" alt="Enter Once" style="width: 12px; height:
9px;" src="ui/uitk/images/s.gif">
<label for="d113353e925">ABC</label>
</td>
<td>
<span title="">XYZ</span><br>
</td>
</tr>

What i want is to get the 'XYZ' value by passing label text = 'ABC'. I
have read something about nextSibling,following-sibling etc. but not
able to frame xpath expression, i am guessing it should be something
like

selenium.getText("//label[text()='ABC']/following-sibling::td");

any help is appreciated.
thx.

t_brc

unread,
Mar 14, 2012, 6:14:11 PM3/14/12
to Selenium Users
I think i found the solution using CSS Selector

selenium.getText("css=tr td.label-colum:contains('ABC')+td")

thx.

Jim Evans

unread,
Mar 15, 2012, 12:53:40 AM3/15/12
to seleniu...@googlegroups.com
Please note that this CSS selector will not work with WebDriver. The :contains() pseudoselector is not part of any CSS standard released by the W3C. It is an extension provided by Sizzle, which is the CSS selector engine used by jQuery (and Selenium RC).

Jayaraman - Inspired to become Software Architect

unread,
Mar 15, 2012, 1:33:42 AM3/15/12
to seleniu...@googlegroups.com
Can you plz try with this one.
 
selenium.getText("//td[@class='class="label-column">']/following-sibling::td");
 
-Jay!!


--
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.


Prasath Sankarapandian

unread,
Mar 15, 2012, 7:25:25 AM3/15/12
to seleniu...@googlegroups.com
This should work for you..

selenium.getText("//label[text()='ABC']/following::span[1]");

The reason it was not working was you were trying to get the sibling of "label" tag.

following::a

Selects the first matching node following in document order, excluding descendants. In other words, the following axis will scan through every node in document order, starting with getNextSibling().

You can also try this
//parent::label[text()='ABC']/following::td/span[1]

Have fun :)
--
Ever Loving Friend,
Prasank.

t_brc

unread,
Mar 15, 2012, 12:51:11 PM3/15/12
to Selenium Users
Thanks guys for you inputs..appreciate it..!

@ Jim : Thanks for letting us know on the css standards and
compatibility with Web Driver, currently we are using RC, but very
soon we will be migrating over to web driver.
@ Prashant : your trick worked...and thanks for the detail
explanation... :)

On Mar 15, 4:25 am, Prasath Sankarapandian <pras...@gmail.com> wrote:
> This should work for you..
>
> selenium.getText("//label[text()='ABC']/following::span[1]");
>
> The reason it was not working was you were trying to get the sibling of
> "label" tag.
> following::a
>
> Selects the first matching node following in document order, excluding
> descendants. In other words, the following axis will scan through every
> node in document order, starting with getNextSibling().
> You can also try this
> //parent::label[text()='ABC']/following::td/span[1]
>
> Have fun :)
>
> On Thu, Mar 15, 2012 at 4:33 PM, Jayaraman - Inspired to become Software
>
>
>
> Architect <electrical.i...@gmail.com> wrote:
> > Can you plz try with this one.
>
> > selenium.getText("//td[@class='class="label-column">']/following-sibling::td");
>
> > -Jay!!
>
Reply all
Reply to author
Forward
0 new messages