0

I want to validate the maximum character limit of the text field in webdriver/java

  • The maxlength attribute of HTML elements? Or is it imposed via javascript? – FDM Apr 9 '15 at 6:43
  • HTML Element FDM – Shanmuga Raj Apr 9 '15 at 7:39
  • In that case: driver.findElement(By.Id("test")).getAttribute("maxlength") will give you the maxlength value, which you can check against whatever variable you need to – FDM Apr 9 '15 at 7:46
  • FDM, I wanna insert max character(not manually) and check whether the alert is populating for maximum character.. – Shanmuga Raj Apr 9 '15 at 7:55
  • Provide the source code on what type of alert the page displays, thanks. – FDM Apr 9 '15 at 8:04
1

If you have some input fields, most likely you also have some limitations related to max. number of chars which user can enter there.

Let's say you have text input field which allows user to enter up to (and inclusive) 255 chars. In this case simplified test scenarios will be:

  1. User enters any number of valid chars (the number of chars should be <255) -> no error message should be shown next to input field
  2. User enters 255 valid chards to input field -> no error message should be shown next to input field
  3. User enters any number of valid chars (the number of chars should be >255) -> appropriate error message should be shown next to input field.

You can pretty easilly implement those scenario using webdriver and java.

For all 3 scenarios you have to implement additional method which will generate random string of specific lenght. You can find here some examples of such methods.

  • hi Viktor Malyi, thanks for the answer, in my case the maxlength character is 154, how can i check for the character limit(153,154,155), can u please provide the code.....thanks in advance – Shanmuga Raj Apr 9 '15 at 7:36
  • Just follow the link at the end of my answer. I've changed it in order to point out at example with java code – Viktor Malyi Apr 9 '15 at 9:12
  • @ViktorMalyi how about the basic scenario where the maxlength attribute blocks any excess characters? In this case, you would try to enter 300 characters but only 255 are actually present as value. – FDM Apr 9 '15 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.