我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
显然,这是Chrome驱动二进制文件中“不会修复”错误的结果。
一个对我有效的解决方案(我们的里程可能有所不同)可以在这个谷歌小组讨论中找到,评论#3:
https://groups.google.com/forum/?fromgroups= !主题/ selenium-developer-activity / DsZ5wFN52tc
相关的部分在这里:
从那以后,我通过直接导航到的href来解决这个问题 跨度的父锚。 driver.Navigate () .GoToUrl (driver.FindElement (By.Id (embeddedSpanIdToClick)) .FindElement (By.XPath(“。”)).GetAttribute(“href”));
在我的例子中,我使用的是Python,所以一旦我得到了所需的元素,我就简单地使用
driver.get(ViewElm.get_attribute('href'))
我希望这只工作,但是,如果你试图点击的元素是一个链接…
其他回答
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))))
您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。
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);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.<Id or anything>));
希望这能有所帮助。
我在使用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" ...