'How do I check if a WebElement is a positive number in Selenium Java?

So, I have a WebElement and I need to check if this element is a positive number; how do I do this in Java using Selenium?

The only thing I was able to do, so far, is a @FindBy(xpath), but I could not do the Actions part cause I have no idea on how to verify if the element is a positive number.

Thanks in advance.



Solution 1:[1]

WebElement myElement = driver.findElementByXpath("theXpath");
// or read the attribute value 
String text = myElement.getAttribute("text");
int number = Integer.parseInt(text);
if (number > 0) {
  // positive
}
else {
  // negative 
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tal Angel