Make Selenium Easy

How To Solve – IllegalArgumentException: Keys to send should be a not null CharSequence

IllegalArgumentException is another frequently faced exception in Selenium WebDriver specially by beginners. So in his post, I will explain a reason of occurrence of this exception.

If you try to type something in to an input box and input string is either null or length of input string is zero, sendKeys() will throw an exception as – IllegalArgumentException: Keys to send should be a not null CharSequence.

If you see the implementation of sendKeys() method in RemoteWebElemen() then you can check that there are some conditions specified before sending keys to WebElement.

If the input string is null or length of input string is zero then throw an exception called IllegalArgumentException with the message Keys to send should be a not null CharSequence.

You will get above exception for both @Test method above.

There is a small catch. Guess the output if we pass value in sendKeys as :-

You will NOT get IllegalArgumentException- Keys to send should be a not null CharSequence as “” is considered as input “” i.e. with length as 1.

You can download/clone above sample project from here.

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

Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.

Many other topics you can navigate through menu.

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.

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.

How To Solve – IllegalArgumentException: Keys to send should be a not null CharSequence

by Amod Mahajan time to read: 1 min
0
%d bloggers like this: