简体   繁体   English

如何检查 Selenium Java 中的 WebElement 是否为正数?

[英]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;所以,我有一个 WebElement,我需要检查这个元素是否为正数; how do I do this in Java using Selenium?我如何使用 Selenium 在 Java 中执行此操作?

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.到目前为止,我唯一能做的就是@FindBy(xpath),但我无法执行操作部分,因为我不知道如何验证元素是否为正数。

Thanks in advance.提前致谢。

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 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM