我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我遇到了这个问题,它似乎是由(在我的情况下)点击一个元素,弹出一个div在前面点击的元素。我通过在一个大的try catch块中包装我的点击来解决这个问题。
其他回答
在chromedriver中似乎有一个bug(问题是它被标记为不会修复) ——> GitHub链接
(也许是对“自由赞助者”的悬赏?)
在第27条评论中提出了一个解决方案。 也许这对你有用
我在使用xvfb-run运行测试时遇到此错误。他们在当地工作得完美无缺。使用chrome, webdriver / chromedriver / chrome / java等版本都相同。
在chromedriver - GitHub Link中,“不会修复”的bug由Tony Lâmpada指出,这可能与屏幕上可见/不可见的内容有关。
xvfb-run的帮助信息如下所示:
-s ARGS --server-args=ARGS arguments (other than server number and
"-nolisten tcp") to pass to the Xvfb server
(default: "-screen 0 640x480x8")
更改xvfb的分辨率可以消除错误:
xvfb-run -s "-screen 0 1280x1024x16" ...
有趣的是,我花了这么多时间研究各种各样的答案,没有人尝试过显而易见的答案,当然,我也没有。如果您的页面多次使用相同的id,就像我的页面一样("newButton",),而您想要的id不是第一个找到的,那么您很可能会得到这个错误。最简单的事情(c#):
var testIt = driver.FindElements(By.Id("newButton"));
注意它是FindElements,而不是FindElement。
然后测试从检索中得到了多少结果。如果是第二个,你可以使用:
testit[1].Click();
或者让那些重复使用id的人来修复它们。
在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();
您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。
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);