xpath - proper syntax for following sibling? and text() function

116 views
Skip to first unread message

Ken Mizell

unread,
Jun 19, 2006, 2:06:16 PM6/19/06
to selenium-users...@googlegroups.com
Hi All,
I've been to the xpath tutorial sites:
http://www.zvon.org/xxl/XPathTutorial/Output/example11.html
and
http://www.w3schools.com/xpath/

and it seems that all of their syntax examples are simple ones.
(it's almost like we need an xpath forum on here)

what I'm trying to do is to select an input text box when all of its unique attrributes may be different every time I run the test because the page is created dynamically. What i know is that the input field is located inside a TD and that the preceeding TD will contain a link whose text is "Update".

here's a snippet of the page
<td>
<a href="javascript:__doPostBack('dtgSteps$_ctl5$_ctl0','')" style="color:threeddarkshadow;">
Update
</a>

<a href="javascript:__doPostBack('dtgSteps$_ctl5$_ctl1','')" style="color:threeddarkshadow;">
Cancel
</a>
</td>
<td align="center">
<input name="dtgSteps:_ctl5:_ctl2" type="text" style="width:100px;" />
</td>
<td align="center">
<input name="dtgSteps:_ctl5:_ctl3" type="text" style="width:100px;" />
</td>

and here's what i tried

//a[contains(text(),'Update')]/parent::td::following-sibling/input[@type='text']

first off - I'm not sure that i'm using the text() function correctly... how do you specify an "a" tag which has a text node containing some text "Update"
second - I'm not sure how to reference a parent TD's Following sibling's child (ha that's a cousin... )

the selenium error i got is:
The expression is not a legal expression.

my question... What is a legal expression for my first following cousin 'input' element of an 'a' element with a text node containing 'Update'

Ken Mizell

unread,
Jun 19, 2006, 2:09:14 PM6/19/06
to selenium-users...@googlegroups.com
ok... the snippet of the page actually rendered the HTML instead of showing the HTML..... so I'm re pasting it with &lt and &gt instead of the actual tag wrappers
&lt;td&gt;
&lt;a href="javascript:__doPostBack('dtgSteps$_ctl5$_ctl0','')" style="color:threeddarkshadow;"&gt;
Update
&lt;/a&gt;

&lt;a href="javascript:__doPostBack('dtgSteps$_ctl5$_ctl1','')" style="color:threeddarkshadow;"&gt;
Cancel
&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;input name="dtgSteps:_ctl5:_ctl2" type="text" style="width:100px;" /&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;input name="dtgSteps:_ctl5:_ctl3" type="text" style="width:100px;" /&gt;
&lt;/td&gt;

Ken Mizell

unread,
Jun 19, 2006, 4:41:54 PM6/19/06
to selenium-users...@googlegroups.com
found my own answer.....

//td[child::a[contains(text(),'Update')]]/following-sibling::td/input[@type='text']


i found it by reading this paragraph:

child::planets/child::planet[position() = 4 ]/child::name[position() = 3]—Returns the third &lt;name&gt; element of the fourth &lt;planet&gt; element of the &lt;planets&gt; element.

from here:
http://www.informit.com/articles/article.asp?p=102644

and this paragraph
Nesting Predicates
It's also legal to nest predicates. Here's how you might select all &lt;project&gt; elements that have &lt;name&gt; descendants that in turn have a preceding sibling &lt;active&gt; element:
//project[descendant::name[preceding-sibling::active]]
You can also nest predicates when using compound location paths and even compound predicates.

from here:
http://www.informit.com/articles/article.asp?p=102644&seqNum=3

Reply all
Reply to author
Forward
0 new messages