我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
在Rselenium中,当链接位于顶部窗口边框时,代码多次成功地使用了这种情况。简单的解决方案是使用sendKeysToElement(),如下所示。
if (unlist(webElem$isElementDisplayed())) {
webElem$sendKeysToElement(list(key = "up_arrow")) # Add "up arrow"..
webElem$clickElement() # ... before $clickElement
其他回答
当我试图单击页面上的单选按钮时,我遇到了同样的异常。我使用下面的Javascript并使用IJavaScriptExecutor执行。 c#示例
string script=" function clickCharity() {"+
"var InputElements = document.getElementsByName('Charity');"+
"for (i=0; i<InputElements.length; i++){"+
"if(InputElements[i].getAttribute('value') == 'true')"+
"{"+
"InputElements[i].click();"+
"}"+
"}"+
"}";
var js=WebDriver as IJavaScriptExecutor;
js.ExecuteScript(script);
可能有很多因素会抛出这个错误。 首先,dom可能会在selenium webdriver捕获元素之后发生变化,或者在捕获元素之前元素中使用的所有java脚本都没有加载成功。 要解决这个问题,我们需要使用javascript等待或ajax等待如下。
wait = new WebDriverWait(driver, 30);
wait.until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
e_driver = new EventFiringWebDriver(driver);
其次,大多数提供软件qa服务的公司的工程师尝试使用java脚本执行器进行单击操作。
如果这也不起作用,那么使用Actions类执行action。
我在点击Angular Material菜单中的一个按钮时就遇到了这个问题。每当我单击菜单中的按钮时,.cdk-overlay-窗格就会收到单击。解决方案是增加菜单内按钮的z-index。
.cdk-overlay-pane button {
z-index: 1001;
}
如果页面中已经加载了jQuery,可以执行以下javascript命令:
"$('#" + element_id + "').click()"
使用python executor的示例:
driver.execute_script("$('#%s').click()" % element_id)
我有另一个bug,在Chrome和Poltergeist上的find_link无法单击一个带有EM标签和一些文本的A标签,尽管它在Firefox和rack_test中工作得很好。解决方案是将click_link(link)替换为:
find('a em', text: link).click