我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我也遇到了同样的问题,花了好几个小时才找到解决办法。我试着用量角器点击一个长ngGrid底部的单元格。这是我的ngrrid html的快照:
....many rows here..
<!- row in renderedRows ->
<!- column in renderedColumns ->
<div ...> <a ngclick="selectRow(row)"...>the test link 100000</a>...
....
所有的点击功能都不能工作。解决方案是在元素的当前范围内使用evaluate:
element(by.cssContainingText("a", "the test link 100000"))
.evaluate("selectRow(row)")
其他回答
我得到这个bug是因为我测试了一个悬停,然后需要点击工具提示下面的链接。解决方案是添加page.find('.sp-logo')。鼠标悬停在click_link之前以获得工具提示。
你可以用JS模拟点击:
public void click(WebElement element) {
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("document.elementFromPoint(" + element.getLocation().x + "," + element.getLocation().y + ").click();");
}
ruby / watir-webdriver /铬
我用了下面的技巧,看起来很管用:
#scroll to myelement
@browser.execute_script "window.scrollTo(#{myelement.element.wd.location[0]},#{myelement.element.wd.location[1]})"
# click myelement
myelement.when_present.fire_event("click")
我在使用clj-webdriver (Selenium的clojure端口)时也遇到了同样的问题。为了方便起见,我只是将前面的解决方案翻译为clojure。你可以在点击之前调用这个函数来避免这个问题。
(defn scrollTo
"Scrolls to the position of the given css selector if found"
[q]
(if (exists? q)
(let [ loc (location-once-visible q) jscript (str "window.scrollTo(" (:x loc) "," (:y loc) ")") ]
(execute-script jscript))))
可能有很多因素会抛出这个错误。 首先,dom可能会在selenium webdriver捕获元素之后发生变化,或者在捕获元素之前元素中使用的所有java脚本都没有加载成功。 要解决这个问题,我们需要使用javascript等待或ajax等待如下。
wait = new WebDriverWait(driver, 30);
wait.until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
e_driver = new EventFiringWebDriver(driver);
其次,大多数提供软件qa服务的公司的工程师尝试使用java脚本执行器进行单击操作。
如果这也不起作用,那么使用Actions类执行action。