Selenium循环并迭代选中复选框



在这个网站https://icem.data-archive.ac.uk/#step1上,我必须创建一个大循环,在浏览整个网站后,迭代地检查年份框。

count = 0
listofyears = webD.find_elements_by_xpath('//input[@type="radio"]')
listofyears = webD.find_elements_by_css_selector("#input li")
lengthyears = len(listofyears)

for i in range(lengthyears):
elem.click()

然后继续导航。这行不通。我如何循环周围的复选框与硒迭代?

点击7年这个小演示将允许你使用driver.back(),如果你这样选择的话。

wait = WebDriverWait(driver, 5)
driver.get("https://icem.data-archive.ac.uk/#step1")
listofyears=wait.until(EC.presence_of_all_elements_located((By.XPATH, "//div[@ng-repeat='year in years']/label/input")))
print(len(listofyears))
for i in range(1,len(listofyears)+1):
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[{}]/label/input".format(str(i))))).click()
time.sleep(5)

进口
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

最新更新