问题描述
<h1 class="style-scope group-search" data-group-search="false" style="display: none;">Searching...</h1>
我需要使用selenium-java获取从false变为true的值,因此我可以创建一个preconditionWait,等待该值返回true,以便继续该方法。
1楼
缺少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`
2楼
在搜索文本时,该布尔值可能会更改。 因此,您可以使用getAttribute()方法获取Web元素的布尔值。
WebElement element = driver.findElement(By.xpath("//h1[contains(text(),'Searching')]"));
boolean isSearch = element.getAttribute("data-group-search");