Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 元素单击Selenium中的InterceptedException(当元素仅部分模糊时)_Python_Selenium_Selenium Webdriver_Selenium Webdriver Python - Fatal编程技术网

Python 元素单击Selenium中的InterceptedException(当元素仅部分模糊时)

Python 元素单击Selenium中的InterceptedException(当元素仅部分模糊时),python,selenium,selenium-webdriver,selenium-webdriver-python,Python,Selenium,Selenium Webdriver,Selenium Webdriver Python,我正在使用硒进行测试。我想点击一个元素。该元素非常容易单击和可见,但恰好该元素的中点被遮挡,从而导致错误 这是一个MCVE: HTML代码: 钮扣{ 宽度:90vw; 高度:90vh; 位置:固定; 顶部:5vh; 左:5vw; } .掩护{ 背景:灰色; 不透明度:0.3; 宽度:80vw; 高度:80vh; 位置:固定; 顶部:10vh; 左:10vw; } 点击我! 我挡道了! Python selenium代码: 从selenium导入webdriver driver=webdriv

我正在使用硒进行测试。我想点击一个元素。该元素非常容易单击和可见,但恰好该元素的中点被遮挡,从而导致错误

这是一个MCVE:

HTML代码:


钮扣{
宽度:90vw;
高度:90vh;
位置:固定;
顶部:5vh;
左:5vw;
}
.掩护{
背景:灰色;
不透明度:0.3;
宽度:80vw;
高度:80vh;
位置:固定;
顶部:10vh;
左:10vw;
}
点击我!
我挡道了!
Python selenium代码:

从selenium导入webdriver
driver=webdriver.Chrome()
驱动程序。隐式等待(10)
驱动程序。获取(“https://blissfulpreciouslanservers--five-nine.repl.co/")
按钮=驱动程序。通过标签名称(“按钮”)查找元素
按钮。单击()
结果:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button onclick="alert('hi');">...</button> is not clickable at point (451, 450). Other element would receive the click: <div class="cover">...</div>
selenium.common.exceptions.element单击拦截异常:消息:元素单击拦截:元素。。。在点(451450)处不可单击。其他元素将收到单击:。。。
这似乎是硒的一个相当可悲的限制。按钮是可点击的,只是不是在所有点。我不想摆弄滚动和坐标

一般来说,关于例外情况有许多类似的问题,例如:

然而,这些问题从来都不是关于一个只是部分模糊的元素,所以我还没有找到我自己问题的正确答案。其他问题的答案一般分为以下几类:

  • 等待元素可单击。这不适用
  • 使用动作链,例如
    动作链(驱动程序)。将\u移动到\u元素(按钮)。单击()。执行()。这没有帮助,因为
    。将\u移动到\u元素()
  • 使用JavaScript执行单击。看起来我可能不得不求助于此,但这很不令人满意。我仍然想验证元素是否至少在某个地方可以单击,而不是绕过所有检查

  • 您是否尝试将
    类添加到按钮中,然后搜索该类?例如:

    <button class="btn" onclick="alert('hi');">
      Click me!
    </button>
    

    与此响应类似,动作链也可以在之后按偏移量移动,因此您可以移动到某个x,y位置。@arundeepchohan手动这样做会使测试更难编写和维护。我想避免它。我在查找元素时没有问题,问题在于单击它。
    driver.findElement(By.className("btn")).click();