-1
Suppose I have a field that has a limit of 15 characters.
In my test i add 16 characters.
How do I validate that they were entered only 15 characters in the field?
browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-valid ui-inputtext ui-corner-all ui-state-default ui-widget']")).sendKeys("1236767676786983");
WebElement campoID = browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-valid ui-inputtext ui-corner-all ui-state-default ui-widget']"));
String texto = campoID.getText();
assertEquals("123676767678698", texto);
Imart, thanks for the feedback! I tried, but the test returns error! Could you help me?
browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-valid ui-inputtext ui-corner-all ui-state-default ui-widget']")).sendKeys("1236767676786983");
WebElement campoID = browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-valid ui-inputtext ui-corner-all ui-state-default ui-widget']"));
String texto = campoID.getText();
assertEquals(15, texto.length());
Erro: Expected :15
Actual :0
However I filled the field with character!– Estevao FPM
Could someone help me?
– Estevao FPM
Stephen, I edited the answer with what you need to run this test. Give a ok if it worked!
– lmart
Imart, I appreciate the feedback! However, keep giving Expected :2 Actual :0 .... What can it be? browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-Valid ui-inputtext ui-corner-all ui-state-default ui-widget']"). Sendkeys("1236767676786983"); Webelement fieldID = browser.findElement(By.xpath("//input[@class='form-control ng-untouched ng-pristine ng-Valid ui-inputtext ui-corner-all ui-state-default ui-widget']")); String text = fieldID.getattribute("value"); assertEquals(15, text.length());
– Estevao FPM
Could you assist me
– Estevao FPM
Dude, check if the xPath you are using is correct, if yes it tries to click off the element, it can be on the label of the element itself but tries to click off the input. This should be right, if not, look in the html where is the value you typed and sent here. uses the function the browser nuisance.
– lmart
Imart, I will check! I’m traveling. As soon as I return already valid! Thanks already!
– Estevao FPM