Could someone help with the following scenario.
In a textfield, i will give input say
String input1 = "120.3456";
But system will automatically take 2 decimal points and displays "120.35" Now i will store using getAttribute("value") into a different string say
String getValue = driver.findElement(By.xpath("html/....xpath of the text field")).getAttribute("value");
How can i validate that my given input value is rounded to 2 decimal points in Selenium Webdriver? Would be grateful if someone can provide me the best approach. Thanks in advance
Try as below :-
String input1="120.3456";
String getValue = driver.findElement(By.xpath("html/....xpath of the text field")).getAttribute("value");
String str = new BigDecimal(input1).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
return str.equals(getValue)
Hope it helps...:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With