I want to check the validation of an input field that what is the number of character it accepts?

Suppose an username field is allowed to accept 15 characters then how can I automate this test?

  • Has the input field a length of 15 character or will throw a error message when you type more characters and submit it?
    – Twaldigas
    Jun 20, 2014 at 12:10
  • The thing is I don't know how many character it will accept. Is it you want me to do hit and try? Jun 20, 2014 at 12:12
  • Why don't you either ask the devs or do a one-time manual test to find out? Are you trying to automate finding out how many characters it accepts? Jun 20, 2014 at 20:27
  • No I am trying to know what would be the exact no of character a given input field will accept so that I can automate with positive and negative test cases on basis of that. Jun 23, 2014 at 9:45

4 Answers 4


It depends on implementation of input field.

1) All major browsers support maxlength attribute.
Look at source code of the page and verify if the input field has it.

2) Or you can enter very long text in the field and see what happens.


This is what I'd do:

  1. Insert a stupidly big number of characters (1000 for example)
  2. Click somewhere else in order to remove the focus from the input field (to let the app process, at least this is how our app works)
  3. Check the number of characters still in the input field, this way you'll now the max number.

Now, this is probably not the right approach, you should have some spec saying how many chars it should allow, but if you don't know....


You should develop your test cases before you automate them. In this case, if you don't know the limit, you should check the requirements, check the spec, or ask a developer what the limit was intended to be. Otherwise, how would you know the limit you found was the one that was meant to be there?

Worst case, you can check it manually by typing until you hit a limit and then counting the number of characters, and use that number.


Here is some pseudo code to find the max-length of an input field. After a form submit you can check the database indeed saved the data correctly.

function maxLength(input) {

    while ( current != length ) {
     current = input.value.length()
     value = input.value
     input.sendKeys(value + randomNewChar())
     length = input.value.length()

    return length

Be careful the length could be infinite and crash your browser or test.

Your Answer

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

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