使用以下二进制文件集:
- Selenium v3.141.0
- ChromeDriver v80.0
- Chrome Version 80.0
您可以使用以下更新的代码块作为解决方案:
from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECoptions = webdriver.ChromeOptions() options.add_argument("start-maximized")options.add_experimental_option("excludeSwitches", ["enable-automation"])options.add_experimental_option('useAutomationExtension', False)driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')driver.get("https://www.inipec.gov.it/cerca-pec/-/pecs/companies")WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECtOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
Original solution
在https://www.inipec.gov.it/cerca-pec/-/pecs/companies要在reCAPTCHA复选框上
调用的URL中,您需要:click()
诱导WebDriverWait获得所需的帧并切换到该帧。
诱导WebDriverWait使所需的元素可单击。
您可以使用以下解决方案:
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.options import Options options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('disable-infobars') driver = webdriver.Chrome(executable_path=r'C:WebDriverschromedriver.exe', chrome_options=options) driver.get("https://www.inipec.gov.it/cerca-pec/-/pecs/companies") WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']"))) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@]/div[@]"))).click()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)