Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

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

Posted on 03/16/2025 By admin

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.

package BasicSeleniumConcepts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class IllegalArgumentExceptionExample {

        @Test
        public void googleSearch1() {
                WebDriverManager.chromedriver().setup();
                WebDriver driver = new ChromeDriver();
                driver.get("https://www.google.com");
                // Typing null search keyword
                String inputString = null;
                driver.findElement(By.name("q")).sendKeys(inputString);
        }
        
        @Test
        public void googleSearch2() {
                WebDriverManager.chromedriver().setup();
                WebDriver driver = new ChromeDriver();
                driver.get("https://www.google.com");
                // no passing any value in sendKeys
                driver.findElement(By.name("q")).sendKeys();
        }
}

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 :-

@Test
public void googleSearch3() {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        // no passing any value in sendKeys
        driver.findElement(By.name("q")).sendKeys("");
}

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

Uncategorized

Post navigation

Previous Post: API Testing Tutorial Part 2 – Why is API Testing Important?
Next Post: API Testing Tutorial Part 11 – Difference Between SOAP and Rest Web Services or API

Related Posts

November 17, 2018 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Untitled Diagram.jpg – Make Selenium Easy Uncategorized
Interview Experience at CTS (Cognizant) Bangalore for Selenium Java Profile ( Sep – 2019) Uncategorized
TestNG Tutorials 46: Overriding Parameters in TestNG | Make Selenium Easy Uncategorized
July 14, 2018 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark