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. 在其他CSS选择器上使用元素ID /类名称
- 2. org.openqa.selenium.ElementNotVisibleException当元素实际上可见
- 3. org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能不会与
- 4. Python Selenium CSS选择器:元素不可见
- 5. 带有id的可见元素的jQuery选择器like
- 6. WPF基于组合选择的UI元素的可见性
- 7. 尝试选择由子元素元素
- 8. PrototypeJS:选择可见元素
- 9. 如何使用XPath或CSS选择可见元素?
- 10. LESS CSS选择器组合不:和伪元素
- 11. CSS选择器“合并”元素
- 12. 硒的HtmlUnit org.openqa.selenium.ElementNotVisibleException:您可能只对可见元素
- 13. SelectorGadget选择不可见元素
- 14. 选择输入场 - 元素不可见
- 15. JQuery/Javascript选择不可见元素
- 16. 与其他选择器一起使用ID选择器
- 17. 如何为包含其他元素的元素编写CSS选择器?
- 18. 选择元素而不使用类/ ID
- 19. 选择不同于单击的元素的其他元素
- 20. 选择元素及其后代
- 21. CSS语法选择类通过其ID标识的元素的
- 22. Primefaces CSS中的“元素”选择器CSS
- 23. 组合CSS选择器
- 24. 禁用元素的CSS选择器
- 25. CSS - 选择其间的元素
- 26. CSS选择器来隐藏文本节点而不是其他子元素
- 27. 如何筛选被其他元素隐藏的“可见”jQuery元素?
- 28. 比较数组元素并尝试向其他数组添加不相似的元素不工作?
- 29. 尝试使用CSS类与Nth-child选择器一起使用
- 30. 使用CSS选择器选择最后一个元素
最初我尝试使用ID,但是当我找到driver.findElement(By(ID))。size()> 1时,我将其更改为CSS选择器。 – Gazal
是否可以请您分享HTML代码段,这将有助于识别问题。 –
– Gazal