• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Basic Selenium / Solution for java.lang.illegalstateexception in Selenium Webdriver

Solution for java.lang.illegalstateexception in Selenium Webdriver

September 27, 2015 by Mukesh Otwani 7 Comments

Solution for java.lang.illegalstateexception in Selenium Webdriver

Hello Everyone Welcome back to Selenium Webdriver tutorial series. Today in this article we are going to discuss one exception which everyone has faced while working with other browsers.

By default, Selenium works with Firefox without any driver but while working with other browsers like Chrome, IE, Opera and so on we need to use third party drivers and specify the path of them.

You can download all third party driver from Selenium official website

 

 java.lang.illegalstateexception in Selenium Webdriver

The root cause of  java.lang.illegalstateexception is we have not specified the path of the driver with the system property.

Until you do not specify the driver details Selenium Webdriver will throw  java.lang.illegalstateexception.

 

I have faced a couple of exceptions while working with Selenium Webdriver and finally came across the solution for all.

Check below articles which will help you to understand which exceptions can come and how to handle them and it is one of the most important interview question as well.

 

What is exception ?

Type of Exceptions in Selenium Webdriver?

Handle Stale Element References Exception

Element not visible exception

F.QueryInterface is not a function

 

For java.lang.illegalstateexception we have to use System class and method called setProperty which will accept key and value pair.

For Chrome what changes we have to make

System.setProperty("webdriver.chrome.driver","path of the chromedriver.exe");

WebDriver driver=new ChromeDriver();

 

 

For IE Browser below changes has to be done

System.setProperty("webdriver.ie.driver","path of the chromedriver.exe");

WebDriver driver=new InternetExplorerDriver();

 

I do not have enough content for this because this exception is just because of small mistake.

If you would like to know how to start with IE and Chrome browser then below article will help you.

 

Execute Selenium Script in Chrome Browser

Execute Selenium Script in IE Browser. 

 

Please share your thoughts or view in the comment section.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

 

Filed Under: Basic Selenium Tagged With: java.lang.illegalstateexception

Reader Interactions

Comments

  1. kranthi says

    November 29, 2020 at 11:19 PM

    what about edge driver? Any one working on Edge driver please revert on how to solve this exception.

    Reply
    • Mukesh Otwani says

      November 30, 2020 at 11:44 AM

      Hi Kranthi,

      You need to verify, whether the driver path is correct and logged in user has full privileges on the folder where driver has been placed

      Reply
  2. Gaurav Khurana says

    December 1, 2016 at 9:44 AM

    Good to see that you have even shared a post on a small problem which even indicates the error message clearly.

    Good thing is we came to know one more exception explicitly which can be used in interview Questions

    Reply
  3. Preetish Kumar Mahato says

    September 1, 2016 at 1:00 PM

    finally i solve the error , autully i was not passing the object of FileInputStream into XSSFworkbook .

    Reply
    • Mukesh Otwani says

      September 2, 2016 at 5:56 PM

      Cheers

      Reply
  4. karishma says

    January 22, 2016 at 3:00 PM

    Hi Mukesh,
    Getting “java.lang.IllegalStateException” though I provided key and path value for opera but for chrome its working fine.

    Reply
    • Mukesh Otwani says

      March 3, 2016 at 5:08 PM

      Hi Karishma,

      I have not tried with Opera. If you have find the solution please share with us so it will help others as well.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?