javascript - 有没有办法使用 Selenium 检测是否有元素阻塞了可点击元素?
问题描述
我正在尝试创建一个脚本,该脚本将单击给定 URL 上的每个链接,但偶尔会出现阻止链接的弹出窗口/叠加层。
是否可以使用 Selenium 或 Javascript 检测这些弹出窗口/覆盖?
我试过使用is_displayed
, is_enabled
,EC.element_is_clickable
但似乎没有任何效果。
编辑:我希望找到一种无需单击即可检测阻塞元素的方法。
解决方案
这个使用这个:
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")
希望能帮助到你
推荐阅读
- android - 在 Spinner 模式下自定义 TimePickerFragment 颜色
- ssas - 使用过滤器为另一个层次结构的每个成员计算日期层次结构上的 LIKE FOR LIKE 度量
- visual-studio-code - 如何在 VSCode 中禁用冲突的内置 Markdown 语言功能
- .net - 在 wpf .net 4.8 中从左侧堆叠内容并在右侧堆叠一个按钮
- javascript - 这个斐波那契实例中的原始 num2 是如何更新的?
- performance - 根据 gtmetrix,我的网站速度性能失败,我该如何改进它
- drupal - Drupal Commerce 为购物车添加折扣规则
- laravel - 用户个人资料图片无法在 laravel 8 中显示
- jenkins - 如何在 Jenkins 中使用 Active Choice 参数根据先前的选择输入文本或字符串值
- html - 合并 HTML 和 CSS