【问题标题】:How to fix a problem - Elementclickintercepted exception如何解决问题 - Elementclickintercepted 异常
【发布时间】:2019-10-10 02:27:26
【问题描述】:

我正在使用 Selenium 3.9.0 + GeckoDriver 0.24 + FireFox 58.0.2。

当 webdriver 想要在我的目标站点上单击导航树中的元素时 -> 脚本因 selenium 异常而崩溃:“selenium.common.exceptions.ElementClickInterceptedException:消息:元素在点 (151,823) 处不可点击,因为另一个元素遮住了它”

什么问题,我该如何解决?

我尝试增加 DOM 元素的等待时间,然后硒才会被点击到元素。但这对我没有帮助。 当我使用旧版 selenium (2.53) 和旧版 firefox (45.2.0) 时,该脚本运行良好。该站点中的 HTML 代码没有人更改。

另外,如果我只启动一个测试用例 -> 脚本不会崩溃并成功完成。如果我启动很多测试用例 -> 脚本开始因异常而崩溃。

我使用单独的方法点击元素:

def click(驱动程序,定位器,sleep_time=5,expl_wait=40): """ 等到元素显示并可点击,然后向它发送“点击”。 如果出现问题(NOT NoSuchElementException)将生成 TimeoutException。

:type driver: WebDriver
:type locator: tuple
:param sleep_time: delay before click
:param expl_wait: explicit waiting time for presence of element will found
:type sleep_time: float
:type expl_wait: float
"""

time.sleep(sleep_time)
WebDriverWait(driver, expl_wait, ignored_exceptions=StaleElementReferenceException).until(
    ec.presence_of_element_located(locator))
# additional check were deleted, cause of some unexpected timeout exceptions on it
WebDriverWait(driver, 40).until(ec.element_to_be_clickable(locator))
driver.find_element(*locator).click()
wait_for_loading(driver)

Web 驱动程序应该单击元素,执行一些操作并返回成功或失败的结果。但实际结果是 -> 脚本崩溃,因为 selenium 无法点击元素

【问题讨论】:

    标签: python selenium qa


    【解决方案1】:
    selenium exception: "selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (151,823) because another element obscures it
    

    要解决这个问题,请尝试使用 javaScript Executor 点击元素。

    driver.execute_script("arguments[0].click();",driver.find_element(*locator))
    

    【讨论】:

  • 如果您使用显式等待,请不要使用ec.element_to_be_clickable,在这种情况下使用ec.presence_of_element_located
  • 对于 clickI 使用该代码 - click(driver, design_dialog_locator(param[0][0], param[0][1])) where design_dialog_locator - 这是我的配置文件中的对话框名称。对于 JS click executor,我应该这样写 - driver.execute_script("arguments[0].click()", design_dialog_locator(param[0][0], param[0][1])) ???
  • 如果是函数就继续
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签