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:

[html] FirstName :

[/html]