Basic Selenium

Solution for java.lang.illegalstateexception in Selenium Webdriver

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

 

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

7 thoughts on “Solution for java.lang.illegalstateexception in Selenium Webdriver

  1. kranthi says:

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

    1. 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

  2. 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

  3. Preetish Kumar Mahato says:

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

  4. karishma says:

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

    1. 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.

Leave a 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.