Python selenium复选框单击

2024-06-28 11:30:24 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我用pythonselenium从表中下载数据。但当我想准备数据时,我不能选中“全部切换”复选框。。。。在

即时消息页面:

browser.get("https://gold.jgi.doe.gov/studies?setColumns=yes&Organism.NCBI+Taxonomy+ID=%3D500633")

单击“为表选择列”

^{pr2}$

这里是复选框;切换全部'。。。在

browser.find_element_by_xpath('//*[@id="selectFieldsList"]/thead/tr[2]/td/input').click()

真的尝试了xpath,css选择器。。。。在

这里是html片段:

<table class="selectFieldsList" id="selectFieldsList">

<thead>
        <tr><td colspan="2" align="center">
        Select Fields using the Checkboxes<br>
        <input type="submit" value="Submit" name="fieldSubmit" id="submitMe" class="submitMe">
    </td></tr>


 <!--  add a select all option -->
       <script language="JavaScript">
       function toggle(source) {
           checkboxes = document.getElementsByName('selectField');
           for(var i=0, n=checkboxes.length;i<n;i++) {
              checkboxes[i].checked = source.checked;
           }
       }

       </script>
       <tr><td> <input type="checkbox" onclick="toggle(this)"> Toggle All<br> </td></tr>
<tr><td>* = required column</td><td>&nbsp;</td> </tr>

<tr><td> <input type="button" id="entityFieldSelectorToggle" value="Expand All Fields"> </td>
</tr></thead>
<tbody>

Tags: 数据brbrowseridfieldsinputtypexpath
1条回答
网友
1楼 · 发布于 2024-06-28 11:30:24

不要使用sleep-use-explicit-wait是一个很好的实践,因为即使在找到元素之后,它也将保持5秒的时间。希望对你有用

 from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    driver.get("https://gold.jgi.doe.gov/studies?setColumns=yes&Organism.NCBI+Taxonomy+ID=%3D500633")
    driver.find_element_by_xpath('//*[@id="showColsButton"]').click()
    wait = WebDriverWait(driver, 10)
    element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="selectFieldsList"]/thead/tr[2]/td/input')))
    driver.find_element_by_xpath('//*[@id="selectFieldsList"]/thead/tr[2]/td/input').click()

相关问题 更多 >