嘿我正在使用python selenium从表中下载数据。但是当我想要准备数据时,我无法选择一个复选框'切换所有'....
点击页面:
browser.get("https://gold.jgi.doe.gov/studies?setColumns=yes&Organism.NCBI+Taxonomy+ID=%3D500633")
点击“选择表格列
”browser.find_element_by_xpath('//*[@id="showColsButton"]').click()
这里我们是复选框;切换所有'...
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> </td> </tr>
<tr><td> <input type="button" id="entityFieldSelectorToggle" value="Expand All Fields"> </td>
</tr></thead>
<tbody>
答案 0 :(得分:3)
而不是使用睡眠使用显式等待是一种很好的做法,因为即使在找到元素之后它也会持续相同的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()