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:

Output:

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.
#ThanksForReading
#HappySelenium

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning