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

这里写自定义目录标题

今日做了一个h5网站的下单流程的自动化脚本,到了最后一步提交订单一直报错,尝试了各种定位方式还是报错,报错内容如下:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a data-v-15c2be92="" href="javascript:void(0)" class="checkout__foot-btn all-disable">...</a> is not clickable at point (304, 637). Other element would receive the click: <div class="vc-switch">...</div>
  (Session info: chrome=84.0.4147.105)

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (304, 637). Other element would receive the click:

(Session info: chrome=84.0.4147.105)

原代码:

driver.find_element(By.LINK_TEXT, "确认提交").click()

后来找了解决办法尝试了一下成功了:

element1=driver.find_element(By.LINK_TEXT, "确认提交")
driver.execute_script("arguments[0].click();",element1)

也没有解释为什么会这样查看了execute_script 的用法如下:

    def execute_script(self, script, *args):
        """
        Synchronously Executes JavaScript in the current window/frame.

        :Args:
         - script: The JavaScript to execute.
         - *args: Any applicable arguments for your JavaScript.

        :Usage:
            driver.execute_script('return document.title;')
        """
        converted_args = list(args)
        command = None
        if self.w3c:
            command = Command.W3C_EXECUTE_SCRIPT
        else:
            command = Command.EXECUTE_SCRIPT

        return self.execute(command, {
            'script': script,
            'args': converted_args})['value']

我理解就是应为我定位的元素需要先执行JavaScript才能做操作,不知道理解对不对,希望有大神指出原理谢谢

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>