【问题标题】:java - org.openqa.selenium.ElementNotVisibleException: element not visiblejava - org.openqa.selenium.ElementNotVisibleException:元素不可见
【发布时间】:2018-11-16 04:35:26
【问题描述】:

我正在尝试从搜索栏中选择一个组。关于如何使元素可见的任何提示?

driver.findElement(By.xpath("//div[@id='global-search-box-item-0']")).click();

下面是 HTML 结构。

<div role="option" id="global-search-box-item-0"><i aria-hidden="true" 
class="comments outline circular icon _2BaEJYulOrH2_i6ZYf-DdV" xpath="1" 
style=""></i><div class="_58oiWFV24V4GmIFrAnwPx"><div class="title">**Test 
Automation** HE Community PRIVATE Group</div><div class="description">**Test 
Automation** HE Community PRIVATE Group </div></div></div>>

【问题讨论】:

  • 请显示 HTML 和屏幕截图以说明您要选择的元素。如果您的应用有公共访问 URL,请也提供。
  • 请出示一段代码。
  • 可能是您的 xpath 重复,请仔细检查。

标签: java selenium xpath


【解决方案1】:

如果它不可见,则应更改页面逻辑以使其可见,如果这是您想要的?

您可以使用 javascript 执行程序破解它。

WebElement webElement = driver.findElement(By.xpath("//div[@id='global-search-box-item-0']"));

((JavascriptExecutor)driver).executeAsyncScript("args[0].style.display='block';",webElement);

否则,如果它存在于页面上并且是可见的,那么这个 xpath 只会返回元素的可见版本。

driver.findElement(By.xpath("//div[@id='global-search-box-item-0' and not(ancestor::*[contains(@style, 'display: none')])]")).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多