![](/img/trans.png)
[英]Selenium Webdriver error “Element is not clickable at point” PrimeFaces SelectOneMenu
[英]Selenium WebDriver - Element is not clickable at point, why?
我知道有多个与此主题相关的主题,但我不一定要寻找解决方案,而只是一种解释。 我致力于一个非常大的自动化套件,该套件可以使用浏览器堆栈通过手机测试Web应用程序。 我的稳定性很低..这是由于此错误向我抛出! 有时它会工作,有时却无法。.我不能使用Actions,因为Browserstack不支持。.为什么存在此错误,并且有人可以解决该问题。 我总是使用wait.until(ExpectedConditions)等待一个对象,但是有时这样做还不够好。 由于它是未知错误,因此我无法完全将其捕获为异常。 另外,我们的标准不允许Thread.sleep()。 有任何想法吗? 非常感谢
您正在等待可单击的WebElement,然后再次找到WebElement列表并单击第一个元素。 这不能保证您单击的是等待单击的元素。
public void waitAndClickElement(WebElement element) {
driverWait.until(ExpectedConditions.elementToBeClickable(element)).click();
}
就你而言
public void clickImageView() {
driverWait.until(ExpectedConditions.elementToBeClickable(listImageView)).click() ;
}
由于以下原因,元素通常无法单击。
问题3无法解决,您需要在此等待中修复您的代码,我等待HTML准备就绪,然后验证是否可以单击,这已从我的代码中消除了此类异常
我如何为问题1和2提出解决方案,您只需在单击之前使用我的自定义等待即可。 将此函数称为public static void waitForElementPresent(final By by, int timeout,WebDriver driver)
之后,如果您使用的是其他浏览器,然后是chrome,则调用Scroll到该对象,这将解决您的问题代码
public static void waitForElementPresent(final By by, int timeout,WebDriver driver) {
waitForPageLoad(driver);
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver,40).ignoring(StaleElementReferenceException.class);
/* wait.until(new ExpectedCondition<Boolean>(){
@Override
public Boolean apply(WebDriver webDriver) {
WebElement element = webDriver.findElement(by);
return element != null && element.isDisplayed();
}
}); */
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.presenceOfElementLocated(by));
wait.until(ExpectedConditions.elementToBeClickable(by));
WebDriverWait wait2 = new WebDriverWait(driver, 40);
wait2.until(ExpectedConditions.elementToBeClickable(by));
}
//wait for page to laod
public static void waitForPageLoad(WebDriver driver) {
ExpectedCondition<Boolean> pageLoadCondition = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
这是由于硒的运行速度。 它将在页面加载之前尝试查找元素,从而导致此错误。
对于您提供的代码示例, .until()
返回您正在等待的WebElement
。 您可以使用下面的代码单击它,而不必再次抓取页面。
public void clickImageView()
{
driverWait.until(ExpectedConditions.elementToBeClickable(listImageView)).click();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.