Reputation: 45
I want to extract the value which is appearing on the screen("70") in order to compare it with a value.
Have already tried getText()
, getAttribute
with different value - title, value, innerHTML, innerText. Unfortunately none of them worked.
Any idea on how we can do this?
<label id="current_heat_setpoint" class="e_field_data_text">70</label>
Note :
I'm able to locate the element have have already made sure that it is the right one - getAttribute("id")
returned "current_heat_setpoint".
Upvotes: 2
Views: 1054
Reputation: 473993
As discussed in comments, this looks really like a timing issue - the text of the label is dynamically set and you need to wait for it to appear before getting it. This can be achieved with WebDriverWait
and a custom Expected Condition:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement label = wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return driver.findElement(By.id("current_heat_setpoint")).getText().length() > 0;
}
});
System.out.println(label.getText());
Upvotes: 2