0

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

asked Apr 9, 2015 at 6:40
5
  • The maxlength attribute of HTML elements? Or is it imposed via javascript? Commented Apr 9, 2015 at 6:43
  • HTML Element FDM Commented Apr 9, 2015 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 Commented Apr 9, 2015 at 7:46
  • FDM, I wanna insert max character(not manually) and check whether the alert is populating for maximum character.. Commented Apr 9, 2015 at 7:55
  • Provide the source code on what type of alert the page displays, thanks. Commented Apr 9, 2015 at 8:04

1 Answer 1

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.

answered Apr 9, 2015 at 7:29
3
  • 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 Commented Apr 9, 2015 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 Commented Apr 9, 2015 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. Commented Apr 9, 2015 at 10:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.