Jethro Axel
Jethro Axel

Reputation: 23

how to get an attribute value that returns a boolean in selenium

<h1 class="style-scope group-search" data-group-search="false" style="display: none;">Searching...</h1>

I need to get the value that changes from false to true using selenium-java, so I can create a preconditionWait that waits for the value to return true, in order to continue with the method.

Upvotes: 2

Views: 3986

Answers (2)

Saritha G
Saritha G

Reputation: 2608

While searching for the text, that boolean may changes. So you can get the boolean value of the web element using getAttribute() method.

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

Upvotes: 0

ddavison
ddavison

Reputation: 29032

It's hard to get a working solution for you with the lack of HTML and context, but here's my best..

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`

Upvotes: 1

Related Questions