boolean display = driver.findElement(By.cssSelector(「input#txtkeyword [placeholder ='Job title']」 ))。isDisplayed(); = false boolean select = driver.findElement(By.cssSelector(「input#txtkeyword [placeholder ='Job title']」))。isSelected(); = false boolean enable = driver.findElement (By.cssSelector(「input#txtkeyword [placeholder ='Job title']」))。isEnabled(); = trueorg.openqa.selenium.ElementNotVisibleException:元素不可見/嘗試使用ID以及CSS選擇器的其他組合
0
A
回答
0
元素不可見的原因很多。它可能被彈出窗口覆蓋,DOM仍可能正在加載,您可能需要將其滾動到視圖中。
對於第一個實例,請對失敗截圖並查看是否覆蓋了該元素。我使用下面的cucumber-jvm。你可以谷歌如何做到這一點,無論你使用的任何框架。
@After
public void captureScreenshotOnFailure(Scenario scenario){
try {
if (scenario.isFailed() && driver !=null) {
System.out.println("***>> Scenario failed: "+scenario.getStatus());
try {
driver augemented = new Augmenter().augment(webDriver);
byte[] screenshot = ((TakesScreenshot) augemented).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
if (driver !=null) {
driver.quit();
}
}
}
對於DOM未完成加載,請等待它。
Wait<driver> wait_element = new WebDriverWait(driver, 80);
WebElement jobTitleElement = wait_element.until(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
"input#txtkeyword[placeholder='Job title']")));
如果等待失敗,那麼該元素就不存在了。
如果等待成功,則滾動到該元素。如果元素是一個按鈕,您可以在moveToElement()之後單擊()它。這只是包括代碼才完整。
Actions action = new Actions(driver);
action.moveToElement(jobTitleElement).click().build().perform();
相關問題
- 1. org.openqa.selenium.ElementNotVisibleException:元素不可見
- 2. 在其他CSS選擇器上使用元素ID /類名稱
- 3. org.openqa.selenium.ElementNotVisibleException:元素當前不可見,所以可能不會命令
- 4. org.openqa.selenium.ElementNotVisibleException當元素實際上可見
- 5. css選擇器,具有子元素(及其子元素)的父元素
- 6. org.openqa.selenium.ElementNotVisibleException:元素當前不可見,因此可能不會與
- 7. Python Selenium CSS選擇器:元素不可見
- 8. 選擇沒有選擇器的元素,僅使用元素ID
- 9. 帶有id的可見元素的jQuery選擇器like
- 10. CSS:選擇一個元素及其所有子元素
- 11. CSS id選擇器<a>元素
- 12. 共同元素以及其他合併元素
- 13. WPF基於組合選擇的UI元素的可見性
- 14. 嘗試選擇由子元素元素
- 15. PrototypeJS:選擇可見元素
- 16. 我可以選擇一個不包含其他元素的元素嗎?
- 17. 如何使用XPath或CSS選擇可見元素?
- 18. LESS CSS選擇器組合不:和僞元素
- 19. 如何通過選擇其他元素來製作可見元素?
- 20. 硒的HtmlUnit org.openqa.selenium.ElementNotVisibleException:您可能只對可見元素
- 21. CSS選擇器「合併」元素
- 22. 即使元素可見,也會發生org.openqa.selenium.ElementNotVisibleException
- 23. 選擇輸入場 - 元素不可見
- 24. JQuery/Javascript選擇不可見元素
- 25. SelectorGadget選擇不可見元素
- 26. 與其他選擇器一起使用ID選擇器
- 27. 選擇元素不包含其他
- 28. 拖動元素而不選擇其他
- 29. 我可以選擇CSS父元素嗎?
- 30. 如何爲包含其他元素的元素編寫CSS選擇器?
最初我嘗試使用ID,但是當我找到driver.findElement(By(ID))。size()> 1時,我將其更改爲CSS選擇器。 – Gazal
是否可以請您分享HTML代碼段,這將有助於識別問題。 –
– Gazal