Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WebDriverWait/EC/by-way在python selenium中单击所选元素不起作用_Python_Python 3.x_Selenium_Selenium Chromedriver - Fatal编程技术网

使用WebDriverWait/EC/by-way在python selenium中单击所选元素不起作用

使用WebDriverWait/EC/by-way在python selenium中单击所选元素不起作用,python,python-3.x,selenium,selenium-chromedriver,Python,Python 3.x,Selenium,Selenium Chromedriver,这就是我正在跟踪的医生 这会引发异常: 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 = WebDriverWai

这就是我正在跟踪的医生

这会引发异常:

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()
然而,这是可行的:

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_framecaptcha_iframe之后,如果您切换到iframes的DOM和位于by.XPATH的节点,则iframe_XPATH将不再具有可访问性


因此,如果要跳过driver.switch_至_framecaptcha_iframe line

则仍可以从主DOM访问,问题是…为什么前一行不行?@Andersson我已更新了问题,希望您现在可以撤回关闭请求。好的。现在你能解释一下为什么要单击iframe,而不是iframe中的特定元素吗?我想单击iframe中的特定元素。但是后面的方法对我来说有些有用,我发现这是我能为问题做的最好的方法。这不是问题。嘿,对不起,你能检查一下吗?我又更新了一次以解决这个问题。不行。这就是问题所在。注意,在第二段代码中,您没有切换到iframe。只需将driver.switch\u添加到\u framecaptcha\u iframe,您的第二个代码也将失败,但不会执行任何操作。将\u移动到\u element captcha\u iframe等价物?绝对不会!它允许鼠标悬停在所需的元素上明白了,太好了,当我点击其中的元素时,它就可以工作了。但是为什么我们有了它呢。
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()