Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在表格中标记与特定文本匹配的复选框_Python_Selenium_Checkbox_Html Table_Row - Fatal编程技术网

Python 在表格中标记与特定文本匹配的复选框

Python 在表格中标记与特定文本匹配的复选框,python,selenium,checkbox,html-table,row,Python,Selenium,Checkbox,Html Table,Row,我有一个表(下面的屏幕截图),我想用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:

我有一个表(下面的屏幕截图),我想用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%;">

47
$100,000
1,000
处理。。。
192.168....

快速查看一下,我认为这行需要更改,因为您正在尝试访问
列的
引用id
,它应该是
行的

发件人:

致:

另外,如果@Saifur发表了评论,您的比较是正确的

更新: 我已经运行了一个模拟,如果将
更改为
,简化版:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('your-form-sample.html')
form = driver.find_element_by_id("quotes-form")

rows = form.find_elements_by_tag_name("tr")
for row in rows:
    columns = row.find_elements_by_tag_name("td")
    for column in columns:
        # I changed this to the actual string provided your comparison is correct
        if column.text == 'Xatu Auto Test':
            # you need to change from column to row, and it will work
            row.find_element_by_name("quote_id").click()
以下是输出:


如果看不到完整的代码,很难理解。如果column.text==self.group\u name:
比较正确,您确定
吗?这是我在这种情况下尝试执行的全部代码。哦,很抱歉,我没有解释“self.group\u name”。你可以用“Xatu自动测试”来代替。是的,我相信比较是正确的。如果这是你的意思,我没有发现任何语法错误。谢谢你的回复,这对我很有帮助!虽然.click()对我不起作用,但这很奇怪。当我把它改为.send_keys(keys.SPACE)时,它就成功了。@AlphaFoxtrot,很高兴它能帮上忙。这很奇怪,我在使用Firefox驱动程序,你在使用Chrome吗?我也在使用Firefox驱动程序。这可能是因为我正在测试的应用程序。但是,单击可以在同一域中其他页面上的其他元素上工作。
row.find_element_by_name("quote_id").click()
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('your-form-sample.html')
form = driver.find_element_by_id("quotes-form")

rows = form.find_elements_by_tag_name("tr")
for row in rows:
    columns = row.find_elements_by_tag_name("td")
    for column in columns:
        # I changed this to the actual string provided your comparison is correct
        if column.text == 'Xatu Auto Test':
            # you need to change from column to row, and it will work
            row.find_element_by_name("quote_id").click()