首页 > 解决方案 > 有没有办法使用 Selenium 检测是否有元素阻塞了可点击元素?

问题描述

我正在尝试创建一个脚本,该脚本将单击给定 URL 上的每个链接,但偶尔会出现阻止链接的弹出窗口/叠加层。

是否可以使用 Selenium 或 Javascript 检测这些弹出窗口/覆盖?

我试过使用is_displayed, is_enabledEC.element_is_clickable但似乎没有任何效果。

编辑:我希望找到一种无需单击即可检测阻塞元素的方法。

标签: javascriptpythonselenium

解决方案


这个使用这个:

try:
    element.Click()
except ElementNotClickableException as x:
    //handle not being able to click element here, you can try to select the element by taking the attributes that are returned in the exception message, or check the exception message to see if it really is an ad, something like x.Message.Contains("class=pop-up")

希望能帮助到你


推荐阅读