我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
在Drupal中使用Selenium时:
// Get element.
$element = $this->driver->getElement('xpath=//input');
// Get screen location.
$location = $element->getLocation();
// To make sure that Chrome correctly handles clicking on the elements
// outside of the screen, we must move the cursor to the element's location.
$this->driver->moveCursor($location['x'], $location['y']);
// Optionally, set some sleep time (0.5 sec in the example below) if your
// elements are visible after some animation.
time_nanosleep(0, 500000000);
// Click on the element.
$element->click();
其他回答
当我试图单击页面上的单选按钮时,我遇到了同样的异常。我使用下面的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);
我在点击Angular Material菜单中的一个按钮时就遇到了这个问题。每当我单击菜单中的按钮时,.cdk-overlay-窗格就会收到单击。解决方案是增加菜单内按钮的z-index。
.cdk-overlay-pane button {
z-index: 1001;
}
如果你试图点击一个被禁用的输入或按钮,这种情况也会发生,在这种情况下,元素没有重叠,但它是不可点击的。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.<Id or anything>));
希望这能有所帮助。
我遇到这个是因为这个元素上有一个加载对话框。我只是通过在使用this元素之前添加一个等待来解决这个问题。
try {
Thread.sleep((int) (3000));
} catch (InterruptedException e) {
//
e.printStackTrace();
}
希望这对你有所帮助!