我知道有关于这个主题的几个主题,但我不一定在寻找解决方案,而是一个解释。我在一个非常大的自动化套件上工作,该套件使用浏览器通过手机测试Web应用程序。我的稳定性很低..这是由于这个错误引发了我!偶尔它会工作,偶尔它不会..我不能使用操作,因为Browserstack不支持该..为什么这个错误存在,并有任何人有任何成功解决它。我总是在等待一个使用wait.until(ExpectedConditions)的对象,但有时候这样做效果不好。因为它是一个未知的错误,所以我不能把它作为例外来捕捉。另外,我们的标准不允许使用Thread.sleep()。有任何想法吗?谢谢你这么多Selenium WebDriver - 元素不可点击,为什么?
2
A
回答
1
元素通常不能够点击,由于以下原因。
- HTML是加载和客户端仍然从服务器
- 由于一些对象重复的对象
问题3接收更新滚动时
我怎么做了解决方案的概率lem 1和2,您可以简单地使用我的自定义等待,然后单击。如果你正在使用其他的浏览器之后,Chrome,然后调用滚动到对象,这将解决你的问题 代码
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);
}
0
这是由于的速度,硒运行。它会在页面加载之前尝试查找元素,从而导致出现此错误。
2
您正在等待WebElement可点击,然后再次查找WebElements列表并单击第一个元素。 这并不能保证你点击你等待点击的元素。
public void waitAndClickElement(WebElement element) {
driverWait.until(ExpectedConditions.elementToBeClickable(element)).click();
}
在你的情况,
public void clickImageView() {
driverWait.until(ExpectedConditions.elementToBeClickable(listImageView)).click() ;
}
+0
我会尝试这一点,因为它似乎使很多感觉!谢谢! – Tree55Topz
0
对于您所提供的代码示例中,.until()
返回WebElement
你正在等待。你可以使用下面的代码来点击它,而不是再次抓取页面。
public void clickImageView()
{
driverWait.until(ExpectedConditions.elementToBeClickable(listImageView)).click();
}
相关问题
- 1. selenium webdriver python:元素点不可点击
- 2. Selenium元素不会点击
- 3. Selenium Webdriver等待元素点击?
- 4. 在Selenium webdriver中修复错误“元素不可点击”
- 5. Selenium - webdriver可以找到元素,但不执行点击操作
- 6. Selenium Webdriver - 元素在firefox中不可点击的错误
- 7. 为什么我不能单击Selenium中的元素?
- 8. 元素不可见 - Selenium - Java Webdriver
- 9. Selenium WebDriver Java - 元素不可见
- 10. 找不到点击Chrome webdriver中元素的方法 - Selenium
- 11. selenium webdriver select元素
- 12. 元素不可点击错误Ruby/Watir
- 13. 需要帮助 - Selenium webdriver-点击可见列表中的元素不起作用
- 14. 为什么Selenium在点击Firefox之前将元素移动到顶部?
- 15. 点击java元素scrapy + selenium
- 16. Selenium元素点击,ElementNotInteractableException
- 17. 元素是无法点Selenium webdriver
- 18. Selenium - 无法点击隐藏的元素
- 19. Python Selenium通过xpath点击元素
- 20. 无法点击selenium webdriver中的元素使用phantomjs python
- 21. 元素在Selenium中的点(X,Y)不可点击
- 22. Selenium WebDriver - 点击HOME键
- 23. Selenium Webdriver - 点击横幅
- 24. Selenium Webdriver - 点击隐藏的元素上的多个元素相同的ID
- 25. 元素不可点击硒python
- 26. Selenium WebDriver访问子元素
- 27. 访问元素submitName selenium webdriver
- 28. 寻找Selenium WebDriver的元素
- 29. 如何使用Java在Selenium WebDriver中检查元素是否可点击
- 30. 如何使用Selenium WebDriver和Ruby来确定该元素是可点击的?
你可以张贴一些故障跟踪我们调用这个函数
public static void waitForElementPresent(final By by, int timeout,WebDriver driver)
在此之后?或者任何代码? – jagdpanzer这也可能是一个有争议的问题,但是你需要使用BrowserStack吗? – jagdpanzer
@jagdpanzer,我更新了这篇文章给你一个例子。目前这是我们拥有的最佳解决方案。我们现在正在使用硒电池。 – Tree55Topz