Sunday 6 September 2015

How to Verify the limit of characters of a textbox

If you already know the char limit, then input the text which is more than the permissible limit. For example if max char limit is 30 then send a text with 31 char length and then fetch the text and count the number of character. It should be 30.

Code example is here which is written considering the limit is 30 char :- 

//Data input should be more than 30 chars
driver.findElement(By.id("textfield1")).sendKeys("Testexample1Testexample2Testexa");

//get count of string length
int actualLimit =driver.findElement(By.id("textfield1")).getText().length();

//Assertion
assertEquals(actualLimit, 30);

No comments:

Post a Comment