单击链接时如何克服 Splinter/Selenium 中的'ElementClickInterceptedException”

Mary-Kate Olsen
发布: 2024-10-27 05:01:02
原创
784 人浏览过

How to Overcome

无法单击元素:Splinter / Selenium 中的 ElementClickInterceptedException

使用 Splinter 或 Selenium 抓取网页时,在尝试单击特定内容时遇到困难可能会出现链接或按钮。当网页加载时,会出现此问题,显示一个“loadingWhiteBox”,遮盖了可点击的元素。

尽管“loadingWhiteBox”在几秒钟后消失,但它仍然存在于 HTML 代码中。虽然该框保持可见,但它会阻止尝试单击元素,从而导致以下错误消息:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element 在点 (318.3000030517578,661.7999877929688) 处不可点击,因为另一个元素

遮盖它

要解决此问题并有效地单击所需的元素,请考虑实现以下方法之一:

<code class="python">element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
driver.execute_script("arguments[0].click();", element)</code>
登录后复制

此方法利用execute_script 函数来执行单击所需元素的JavaScript 代码

<code class="python">element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
webdriver.ActionChains(driver).move_to_element(element).click(element).perform()</code>
登录后复制

或者,此方法使用 ActionChains 类将鼠标光标移动到元素的位置并执行单击,从而有效地绕过遮挡元素。

以上是单击链接时如何克服 Splinter/Selenium 中的'ElementClickInterceptedException”的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!