EGHM
EGHM

Reputation: 2140

Selenium selector to select input in second td by text in the first

Looking for a selenium selector that I can use the text in the first td to selected the input in the second.

<tr><th>asdf</th><td><input type="text"></td></tr>
<tr><th>qwer</th><td><input type="text"></td></tr>
<tr><th>rtyu</th><td><input type="text"></td></tr>
<tr><th>fghj</th><td><input type="text"></td></tr>

Upvotes: 0

Views: 2107

Answers (1)

VolkerK
VolkerK

Reputation: 1510

Use this as a document:

<html>
<tr><td>asdf</td><td><input type="text"/></td></tr>
<tr><td>qwer</td><td><input type="text"/></td></tr>
<tr><td>rtyu</td><td><input type="text"/></td></tr>
<tr><td>fghj</td><td><input type="text"/></td></tr>
</html>

Use this as a xpath expression:

//tr/td[text()="asdf"]//following-sibling::td

Here is a nice page where you can test it online and play around till you've got the correct syntax: http://www.mizar.dk/XPath/Default.aspx

Take look at the following-sibling xpath example and the Selenium locator reference.

Answer Updated!

Upvotes: 1

Related Questions