我使用的是Selenium WebDriver,我有一个表格,里面有很多行和列。每行都有自己的复选框以选择此行。 我需要选择确切行的复选框。我正在尝试
driver.find_element_by_xpath("//td[.='jared124']//[@type='checkbox']")
但它不起作用 html代码是:
<tr class="even">
<td>
<input type="checkbox" id="ohrmList_chkSelectRecord_1239"
name="chkSelectRow[]" value="1239">
</td>
<td class="left">
<a href="saveSystemUser?userId=1239">jared124</a>
</td>
</tr>
答案 0 :(得分:0)
阅读xpath follow-sibling,previous-sibling,parent和ancestor。它将帮助您构建xpath定位器。 请尝试以下:
driver.find_element_by_xpath("//input[@value='1239']")
或者您可以使用其值单击复选框:
numpy.where
答案 1 :(得分:0)
使用xpath
定位器
//a[text()='jared124']//preceding::input[@value='1239']
xpath的说明:使用text
方法查找文本jared124
以及<a>
标记,然后使用preceding
关键字查找带有<input>
标记的复选框以及value
属性。