当前位置: 代码迷 >> java >> 如何获取返回硒中的布尔值的属性值
  详细解决方案

如何获取返回硒中的布尔值的属性值

热度:31   发布时间:2023-07-17 20:58:44.0
<h1 class="style-scope group-search" data-group-search="false" style="display: none;">Searching...</h1>

我需要使用selenium-java获取从false变为true的值,因此我可以创建一个preconditionWait,等待该值返回true,以便继续该方法。

缺少HTML和上下文,很难为您找到一个可行的解决方案,但这是我的最好。

bool groupSearch = false;
while (!groupSearch)
    groupSearch = Boolean.parse(driver.findElement(By.cssSelector(".style-scope.group-search")).getAttribute("data-group-search"));

// at this point in the code, the `data-group-search` will be `true`

在搜索文本时,该布尔值可能会更改。 因此,您可以使用getAttribute()方法获取Web元素的布尔值。

 WebElement element = driver.findElement(By.xpath("//h1[contains(text(),'Searching')]"));
 boolean isSearch = element.getAttribute("data-group-search");
  相关解决方案