我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我有同样的问题,尝试了所有提供的解决方案,但它们都不适合我。 最后我用了这个:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));
希望这能有所帮助
其他回答
我有同样的问题,并得到'其他元素将收到点击'错误显示,可见的元素。我发现没有其他解决方案,以触发与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();"
);
结果一切都很顺利
当您使用分辨率大于1024x768的浏览器时,尝试最大化浏览器。
driver.manage().window().maximize();
在测试了所有提到的建议后,没有一个奏效。我写了这个代码。它有效,但并不漂亮
public void click(WebElement element) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
element.click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public void click(String css) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
driver.findElement(By.cssSelector(css)).click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
我在python中运行selenium脚本时遇到了同样的问题。下面是我用来点击元素的:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).click(element).perform()
你也可以使用JavaScript点击和滚动将不需要那么。
IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);