我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我也在努力解决这个问题。代码在FF中工作正常,在Chrome上失败。我试着做的是点击一个复选框——如果它不在视图中,我会滚动到视图,然后点击。即使滚动到视图在Chrome中工作,只有底部几个像素的复选框是不可见的,所以网络驱动程序拒绝点击它。
我的解决办法是:
WebElement element = _sectorPopup.findElement(...);
((Locatable) element).getCoordinates().inViewPort();
try {
element.click();
} catch (Exception e) {
new Actions(getWebDriver()).sendKeys(Keys.PAGE_DOWN).perform();
element.click();
}
Chrome也有sendKeys的问题,使用动作有时是必要的。显然,你需要知道哪个方向和你需要走多少,所以你的里程可能会有所不同。但我更喜欢这个javascript黑客,所以我把它贴在这里,以防别人会发现它有用。
其他回答
你也可以使用JavaScript点击和滚动将不需要那么。
IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);
当您使用分辨率大于1024x768的浏览器时,尝试最大化浏览器。
driver.manage().window().maximize();
在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();
我在点击Angular Material菜单中的一个按钮时就遇到了这个问题。每当我单击菜单中的按钮时,.cdk-overlay-窗格就会收到单击。解决方案是增加菜单内按钮的z-index。
.cdk-overlay-pane button {
z-index: 1001;
}
我也面临着同样的问题,我使用了延迟,这在我这边很有效。Page正在刷新和获取其他定位器。
Thread.sleep(2000);
Click(By.xpath("//*[@id='instructions_container']/a"));