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.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through 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

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: