我知道有關於這個主題的幾個主題,但我不一定在尋找解決方案,而是一個解釋。我在一個非常大的自動化套件上工作,該套件使用瀏覽器通過手機測試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 -python元素不可點擊
- 3. Selenium Webdriver - 元素不可見
- 4. Selenium元素不會點擊
- 5. Selenium Webdriver - 點擊隱藏元素
- 6. Selenium Webdriver等待元素點擊?
- 7. 在Selenium webdriver中修復錯誤「元素不可點擊」
- 8. 如何點擊Selenium WebDriver中不可見的元素?
- 9. Selenium Webdriver - 元素在firefox中不可點擊的錯誤
- 10. Selenium - webdriver可以找到元素,但不執行點擊操作
- 11. selenium python點擊元素什麼也沒有發生
- 12. 爲什麼我不能單擊Selenium中的元素?
- 13. Ruby Selenium Webdriver - 不會點擊?
- 14. 元素不可見 - Selenium - Java Webdriver
- 15. Selenium WebDriver Java - 元素不可見
- 16. 如何等待元素不能使用Selenium Webdriver點擊?
- 17. 找不到點擊Chrome webdriver中元素的方法 - Selenium
- 18. 找不到selenium webdriver元素
- 19. 元素不可點擊錯誤Ruby/Watir
- 20. selenium webdriver select元素
- 21. 需要幫助 - Selenium webdriver-點擊可見列表中的元素不起作用
- 22. 爲什麼Selenium在點擊Firefox之前將元素移動到頂部?
- 23. Selenium元素點擊,ElementNotInteractableException
- 24. 點擊java元素scrapy + selenium
- 25. xpath in selenium點擊元素
- 26. Selenium - 無法點擊隱藏的元素
- 27. 元素是無法點Selenium webdriver
- 28. Python Selenium通過xpath點擊元素
- 29. 爲什麼WebDriver在「點擊」一個元素時不能移動到下一頁?
- 30. Selenium webdriver在點擊之前突出顯示元素
你可以張貼一些故障跟蹤我們調用這個函數
public static void waitForElementPresent(final By by, int timeout,WebDriver driver)
在此之後?或者任何代碼? – jagdpanzer這也可能是一個有爭議的問題,但是你需要使用BrowserStack嗎? – jagdpanzer
@jagdpanzer,我更新了這篇文章給你一個例子。目前這是我們擁有的最佳解決方案。我們現在正在使用硒電池。 – Tree55Topz