我有一个表格(下面的屏幕截图),我希望使用selenium python标记在同一行中包含文本“Xatu Auto Test”的复选框。
我尝试过这两个帖子:
但我无法让这些解决方案适用于我的代码。
我的代码:
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%;">
答案 0 :(得分:0)
快速浏览一下,我认为当您尝试访问column
的{{1}}时,此行需要更改,它应为quote_id
:
自:
row
要:
column.find_element_by_name("quote_id").click()
P.S。如果@Saifur评论过,您可以正确地进行比较。
我已经运行了模拟,如果将row.find_element_by_name("quote_id").click()
更改为column
,简化版本确实会勾选复选框:
row
这是输出: