解决selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted

这篇具有很好参考价值的文章主要介绍了解决selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

用selenium爬数据的时候,明明每一步点击都加了WebDriverWait,但还是爬一会儿就显示如下错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <tr class="even" onclick="onclick_shipinsp(this,'insp')">...</tr> is not clickable at point (509, 404). Other element would receive the click: <div class="blockUI blockOverlay ui-widget-overlay" style="z-index: 1000; position: fixed; opacity: 0;"></div>
  (Session info: chrome=110.0.5481.178)

这里一定要注意后面的这句

“ Other element would receive the click: <div class="blockUI blockOverlay ui-widget-overlay" style="z-index: 1000; position: fixed; opacity: 0;"></div>
  (Session info: chrome=110.0.5481.178)

也就是说我们想点击的按钮没点成,而是被这个覆盖了。
查资料得知:

blockUI 是一个 JavaScript 库,用于创建可定制的页面遮罩和加载指示器。它提供了一个简单的方式来阻止用户在页面加载或执行某些任务时进行交互,并显示一个加载指示器,以提示用户页面正在处理。

解决尝试一:
加一个异常处理块,这里try块中是之前报错的地方,一旦出现异常则对之前bug说明里出现的元素进行隐藏,然后再次尝试点击。

try:
    driver.find_element(By.XPATH,xpath_pattern).click()
except:
    wait = WebDriverWait(driver, 100)
    element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'blockUI blockOverlay ui-widget-overlay')))
    driver.execute_script("arguments[0].style.display = 'none';", element)
    try:
    driver.find_element(By.XPATH,xpath_pattern).click()

尝试之后:比之前多撑了一会儿但在except块中还是会报错找不到元素。

解决尝试二:

        for i in range(3):
            try:
                click_button(driver, index_xpath)
                break
            except:
                # 如果点击元素失败,检查元素是否存在且可见
                block_overlay = driver.execute_script(
                    "return document.querySelector('.blockUI.blockOverlay.ui-widget-overlay')")
                if block_overlay and block_overlay.is_displayed():
                    # 如果元素存在且可见,隐藏元素
                    driver.execute_script(
                        "document.querySelector('.blockUI.blockOverlay.ui-widget-overlay').style.display='none';")
                try:
                    click_button(driver, index_xpath)
                    break
                except:
                    # 如果还是失败,等待一段时间再尝试
                    time.sleep(10)

目前这种解决方法暂时可行。学习爬虫不久,有更好方法的朋友欢迎指教。文章来源地址https://www.toymoban.com/news/detail-511590.html

到了这里,关于解决selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • selenium报错解决:selenium.common.exceptions.WebDriverException: Message(已解决)

    今天使用selenium遇到报错: selenium.common.exceptions.WebDriverException: Message: Service ./windows/chromedriver.exe unexpectedly exited. Status code was: 1 报错截图:   检查了代码没有发现问题,根据报错初步判断问题是出在chromedriver的路径上面,对比之前的代码 乍一看不能发现问题,仔细对比发现是

    2024年02月11日
    浏览(39)
  • 解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu

    运行爬虫代码出现上面的bug bug详细信息如下  解决方法 如下 1.先打开chrome 输入 “chrome://version/”来查看chrome版本 如图我的是96   2.然后访问此网站  http://chromedriver.storage.googleapis.com/index.html   然后选择合适版本的driver   我这边是windows版本的系统所以下载  win32版本的压缩

    2024年02月16日
    浏览(34)
  • 已解决selenium.common.exceptions.TimeoutException: Message: script timeout

    已解决(selenium模块操作浏览器报错)selenium.common.exceptions.TimeoutException: Message: script timeout 粉丝群里面的一个粉丝用selenium模块操作浏览器爬取网页数据,但是发生了报错(跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴

    2024年01月15日
    浏览(28)
  • 【报错解决】selenium.common.exceptions.WebDriverException: Message: invalid argument

    在做Web自动化测试的实验报告的时候遇到一个报错。 运行代码: 报错: selenium.common.exceptions.WebDriverException: Message: invalid argument (Session info: chrome=113.0.5672.92) (Driver info: chromedriver=113.0.5672.63 (0e1a4471d5ae5bf128b1bd8f4d627c8cbd55f70c-refs/branch-heads/5672@{#912}),platform=Windows NT 10.0.19044 x86_64) 这

    2024年02月05日
    浏览(36)
  • selenium.common.exceptions.SessionNotCreatedException: Message: session not created 解决办法

    一、问题原因 报这个错是因为 当前浏览器的版本与 chromedriver.exe的版本不一致了。这个时候你需要先知道自己当前浏览器的版本 ,然后再去下载一个 chromedriver.exe的对应版就好了 二、解决办法 1、查看浏览器版本 帮助-关于Google Chrome https://registry.npmmirror.com/binary.html?path=chro

    2024年02月11日
    浏览(39)
  • 一文解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created

    你遇到的错误消息表明您正在使用的ChromeDriver的版本与您计算机上安装的Google Chrome版本不兼容。ChromeDriver是一个独立的可执行文件,WebDriver使用它来控制Chrome浏览器。要解决这个问题,您有几个可能的解决方案,具体介绍如下所示。 1.修改ChromeDriver的版本 此方法需要首先查

    2024年02月08日
    浏览(36)
  • 解决selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable报错

    这个错误是由Selenium WebDriver引起的,它表示一个元素无法与之交互。 这通常意味着Selenium无法模拟用户与该元素交互的方式,可能是由于以下原因之一: 元素被隐藏了,无法与之交互。 元素被覆盖了,无法与之交互。 元素不可见,无法与之交互。 页面还没有完全加载,元素

    2024年02月14日
    浏览(31)
  • selenium.common.exceptions.WebDriverException: Message: chrome not reachable解决方法

    在 python上使用 selenium 。 一开始还算顺利,但是随着反复执行,处理量变多了。 如果一直等待,最终会出现无法访问 chrome 的错误。 已经添加了driver.quit()。 引入一个新的函数,检查是否有 chrome 驱动程序正在运行,并打印提示,如果有,则杀死所有chrome 驱动程序。 相当于在

    2024年02月16日
    浏览(40)
  • 已解决selenium.common.exceptions.WebDriverException: Message: invalid session id

    已解决selenium循环翻页抛出selenium.common.exceptions.WebDriverException: Message: invalid session id的正确解决方法,亲测有效!!! 粉丝群里面的一个小伙伴遇到问题跑来私信我,想用selenium循环翻页,但是发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,

    2023年04月08日
    浏览(45)
  • 【python selenium报错】selenium.common.exceptions.WebDriverException: Message: <html> 三种解决方案!

    在运行python代码时遇到该问题解决方案三种(我是第三种才解决的,总结一句话:是代理ip的问题★★★): 一、重新安装selenium,可能是缺少某些文件 二、查看chrom的版本,在chrom驱动的官方网站中下载安装适配的版本(版本接近即可),并将其配置到系统环境下,具体步骤

    2024年02月11日
    浏览(50)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包