Make Selenium Easy

How To Verify Maximum Character Limit of an Input Box Through Selenium

Hello Folks,

Recently a guy asked me this question which he was asked in an interview in IBM.

What the ways to test maximum character limit of an input box through Selenium?

To achieve this in Selenium, we have two ways:

Suppose maximum character limit of an input box is 10 characters.

  1. Type more than 10 characters. It will get typed only first 10 characters and remaining will be ignored. Now get the typed value and assert its length to10.
  2. Get the attribute value of “maxlength” and assert it to10. “maxlength” is a property which is defined to set maximum allowed character limit for an input box.

Both ways are correct and can be used whatever you feel easy.

Html Code:

FirstName : <input type="text" name="username" maxlength="10">

Java Code:


Max character functionality is working fine.
Max character limit is set as expected.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

3 thoughts on “How To Verify Maximum Character Limit of an Input Box Through Selenium

  1. Hi Amodh,

    This article is very nice and informative.
    I have got one doubt , what if the maximum length is undefined or not known but definitely there is some restrictions on the number of characters a user can enter into the text field.
    How do you achieve this scenario?

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.