我是 Selenium 的新手,希望能得到一些帮助。想象一下,我们有一个用户可以在其中书写的框;我需要断言文本字段的字段格式正确为 1000000.00 = $1,000,000.00 我正在尝试使用 selenium 和 java 来验证这一点。该字段由下面的 html 表示。
<div id="req8">
<h2>Test #8</h2>
<input id="req8input" type="text" value="Type Number Here">
</div>
我将如何在 Java 中解决这个问题?谢谢!
最佳答案
使用this获取值的正确文本格式,然后您可以对字段的现有文本值进行断言。您也可以使模式特定于区域设置。还有各种其他选择。像这样的东西应该有效。
String value=""1000000.00""
DecimalFormat myFormatter = new DecimalFormat("###,###.##");
String output = myFormatter.format(value);
WebElement webElement= driver.findElement(By.ById("req8input"));
webElement.sendKeys("100);
assertEquals(output, webElement.getAttribute("value"));
关于java - Selenium,验证字段格式是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28591610/