【问题标题】:Is there a way to detect whether there is an element blocking a clickable element using Selenium?有没有办法使用 Selenium 检测是否有元素阻塞了可点击元素?
【发布时间】:2019-05-02 20:46:54
【问题描述】:

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

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

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

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

【问题讨论】:

  • 我建议您在问题中包含一些您尝试过的代码。这将增加获得答案的机会,并减少您的问题被标记和删除的机会。
  • 你能提供弹出/覆盖的 HTML 吗?

标签: javascript python selenium


【解决方案1】:

这个使用这个:

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")

希望对你有帮助

【讨论】:

  • 是否可以在不点击的情况下检测到阻塞元素?我可能应该澄清这一点。对不起
  • 你不能在运行测试之前创建一个脚本来关闭页面中的所有弹出窗口吗?您实际上可以使用 driver.execute_script("arguments[0].click();", element) 单击这些弹出窗口下的元素...更多信息请点击此处stackoverflow.com/questions/34562061/…
猜你喜欢
  • 2014-03-01
  • 1970-01-01
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
  • 2019-09-08
  • 1970-01-01
  • 2011-12-29
  • 2015-07-03
相关资源
最近更新 更多