代码之家  ›  专栏  ›  技术社区  ›  ishandutta2007

在python selenium中单击选定的元素,使用webdriverwait/ec/不会起作用。

  •  0
  • ishandutta2007  · 技术社区  · 7 年前

    这是我要跟踪的医生 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脚本。

    为什么以前的工作看起来更标准?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Andersson    7 年前

    driver.switch_to_frame(captcha_iframe) 您切换到了iframes的dom和node By.XPATH, iframe_xpath 无法访问。

    因此,如果要跳过,它仍然可以从主DOM访问 驱动程序。切换到帧(captcha-iframe) 线