这就是我关注的文件http://selenium-python.readthedocs.io/waits.html
引发异常:
driver = webdriver.Chrome(CHROME_DRIVER_PATH)
iframe_xpath = "//*[@id='targetForCaptcha1']/div/div/iframe"
captcha_iframe = driver.find_element_by_xpath(iframe_xpath)
driver.switch_to_frame(captcha_iframe)
checkBox = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, iframe_xpath)))
checkBox.click()
raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
但这是可行的:
driver = webdriver.Chrome(CHROME_DRIVER_PATH)
iframe_xpath = "//*[@id='targetForCaptcha1']/div/div/iframe"
captcha_iframe = driver.find_element_by_xpath(iframe_xpath)
action=ActionChains(driver)
action.move_to_element(captcha_iframe)
action.click().perform()
以上两个会话是从零开始运行python脚本的独立会话
为什么以前的工作似乎是更标准的工作方式
Iframe是主DOM的一个节点。在调用
driver.switch_to_frame(captcha_iframe)
之后,您切换到iframes的DOM,By.XPATH, iframe_xpath
所在的节点不再可访问因此,如果要跳过
driver.switch_to_frame(captcha_iframe)
行,应该仍然可以从主DOM访问它相关问题 更多 >
编程相关推荐