2012-08-07 135 views
0

尋找硒選擇器,我可以使用第一個td中的文本選擇第二個中的輸入。Selenium選擇器在第一個td中通過文本選擇輸入

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

回答

1

使用此作爲文檔:

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

以此爲XPath表達式:

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

這裏是一個不錯的頁面,您可以在線測試和玩,直到你已得到正確的語法: http://www.mizar.dk/XPath/Default.aspx

看看following-sibling xpath示例和Selenium locator reference

回答更新!