Python 元素单击Selenium中的InterceptedException(当元素仅部分模糊时)
我正在使用硒进行测试。我想点击一个元素。该元素非常容易单击和可见,但恰好该元素的中点被遮挡,从而导致错误 这是一个MCVE: HTML代码: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
钮扣{
宽度: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元素()
您是否尝试将
类添加到按钮中,然后搜索该类?例如:
<button class="btn" onclick="alert('hi');">
Click me!
</button>
与此响应类似,动作链也可以在之后按偏移量移动,因此您可以移动到某个x,y位置。@arundeepchohan手动这样做会使测试更难编写和维护。我想避免它。我在查找元素时没有问题,问题在于单击它。
driver.findElement(By.className("btn")).click();