我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
而不是
webdriver.findElement(By.id("id1")).click();
试着使用
click(By.id("id1"));
void click(final By byLocator) {
waitFor(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
WebElement element = driver.findElement(byLocator);
if (element.isDisplayed()) {
try {
element.click();
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
@Override
public String toString() {
return "Element located " + byLocator + " clicked";
}
});
}
其他回答
这是由以下3种类型引起的:
1.单击该元素是不可见的。
使用Actions或JavascriptExecutor让它点击。
行动:
WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
由JavascriptExecutor:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)"); // if the element is on top.
jse.executeScript("scroll(0, 250)"); // if the element is on bottom.
or
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Webelement);
然后单击元素。
2.在单击元素之前,页面会被刷新。
为此,让页面等待几秒钟。
3.元素是可点击的,但有一个旋转/覆盖在它的顶部
下面的代码将等待覆盖消失
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
然后单击元素。
我遇到了这个问题,它似乎是由(在我的情况下)点击一个元素,弹出一个div在前面点击的元素。我通过在一个大的try catch块中包装我的点击来解决这个问题。
我也遇到了同样的问题,花了好几个小时才找到解决办法。我试着用量角器点击一个长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)")
您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。
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);
错误信息解释:
错误消息只是说,您想要单击的元素存在,但它不可见。它可能被什么东西覆盖,或者暂时看不见。
元素在测试时不可见的原因有很多。请重新分析您的页面,并为您的情况找到合适的解决方案。
特殊情况的解决方案:
在我的例子中,当我刚刚点击的屏幕元素的工具提示出现在我想要点击的下一步元素上时,就发生了这个错误。离焦是我需要的解决方案。
快速解决散焦的方法是点击屏幕另一部分的其他元素,这些元素“没有”反应。点击动作后什么都不会发生。 正确的解决方案是在弹出工具提示的元素上调用element.blur(),这将使工具提示消失。