【发布时间】:2017-03-19 06:34:41
【问题描述】:
我有一个表格(下面的屏幕截图),我想在其中使用 selenium python 标记在同一行中具有文本“Xatu Auto Test”的复选框。
我试过关注这两个帖子:
- Iterating Through a Table in Selenium Very Slow
- Get row & column values in web table using python web driver
但我无法让这些解决方案在我的代码上运行。
我的代码:
form = self.browser.find_element_by_id("quotes-form")
try:
rows = form.find_elements_by_tag_name("tr")
for row in rows:
columns = row.find_elements_by_tag_name("td")
for column in columns:
if column.text == self.group_name:
column.find_element_by_name("quote_id").click()
except NoSuchElementException:
pass
复选框从未被点击,我想知道我做错了什么。
这是我使用 FirePath 检查时的 HTML:
<form id="quotes-form" action="/admin/quote/delete_multiple" method="post" name="quotesForm">
<table class="table table-striped table-shadow">
<thead>
<tbody id="quote-rows">
<tr>
<tr>
<td class="document-column">
<td>47</td>
<td class="nobr">
<td class="nobr">
<td class="nobr">
<td class="nobr">
<a title="Xatu Auto Test Data: No" href="http://192.168.56.10:5001/admin/quote/47/">Xatu Auto Test</a>
</td>
<td>$100,000</td>
<td style="text-align: right;">1,000</td>
<td class="nobr">Processing...</td>
<td class="nobr">192.168....</td>
<td/>
<td>
<input type="checkbox" value="47" name="quote_id"/>
</td>
</tr>
<tr>
</tbody>
<tbody id="quote-rows-footer">
</table>
<div class="btn-toolbar" style="text-align:center; width:100%;">
【问题讨论】:
-
如果没有看到完整的代码,很难理解。你确定
if column.text == self.group_name:比较正确吗? -
这是我在这种情况下尝试做的完整代码。哦,对不起,我没有解释“self.group_name”。您可以将其替换为“Xatu Auto Test”。
-
是的,我相信比较是正确的。如果这就是你的意思,我没有收到任何语法错误。
标签: python selenium checkbox html-table row