我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我有同样的问题,并得到'其他元素将收到点击'错误显示,可见的元素。我发现没有其他解决方案,以触发与javascript点击。
我更换:
WebElement el = webDriver.findElement(By.id("undo-alert"));
WebElement closeButton = el.findElement(By.className("close"));
// The following throws 'Element is not clickable at point ... Other element
// would receive the click'
closeButton.click();
:
((JavascriptExecutor) webDriver).executeScript(
"$('#undo-alert').find('.close').click();"
);
结果一切都很顺利
其他回答
你可以用JS模拟点击:
public void click(WebElement element) {
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("document.elementFromPoint(" + element.getLocation().x + "," + element.getLocation().y + ").click();");
}
您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。
WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
OR
元素是不可点击的,因为它上面有一个旋转/覆盖:
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
OR
Point p= element.getLocation();
Actions actions = new Actions(driver);
actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
OR
如果仍然不能工作,请使用JavascriptExecutor
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", firstbutton);
如果你在conf.js文件中使用下面这行代码,请将其注释掉,然后再试一次
browser.ignoreSynchronization = true;
在我的例子中,它在Firefox中运行正常,但在Chrome中失败了。在Chrome中,在更新Chrome驱动程序版本到最新版本后,该问题得到了修复。
我根据Tony Lâmpada的回答做出了这个方法。它工作得很好。
def scroll_to(element)
page.execute_script("window.scrollTo(#{element.native.location.x}, #{element.native.location.y})")
end