How to Resolve NoSuchSessionException in selenium free?

How to Resolve NoSuchSessionException in selenium?

NoSuchSessionException in Selenium is a tricky issue that requires several techniques to check and follow. In this post, I tried to explain several techniques of how I have resolved one of my cases.NoSuchSessionExpection occurs when we try to perform actions after quitting the session. The classic exception will also guide you further.

The Class Structure of NoSuchSessionException in selenium is as follows:

The details are given here.

public class public class org.openqa.selenium.NoSuchSessionException extends 
//field Information:
public SESSION_ID;
NoSuchSessionException(java.lang.String reason) 
NoSuchSessionException(java.lang.String reason,java.lang.Throwable cause) 

Possible Cause and Solve:

Step-1: Is the Driver Incompatible with Browser?

It is very much possible that our ChromeDriver/ FireFoxDriver/ IEDriver are not compatible with the Chrome, Firefox, IE browser, we are using along with Selenium Client. We need to make sure if they are correct. We also need to check for JDK version compatibility. We need to downgrade or upgrade the versions to check for a solution. Ideally, all the latest versions should resolve our issue. NoSuchSessionException in selenium can occur due to this.

-> Download chrome driver from –
-> Download firefox driver from –
-> Download IE driver from –

Step-2: What are we using driver.close() or driver.quit()?

Are we using driver.close()? Check if there are some steps left after the driver is closed. If so, driver.close() closes the browser and as there is no active browser, the driver quits. If we code haphazardly, this issue may appear. We need to define a teardown method after the test to call driver.quit().

See also  Class OutputStreamWriter in Java

This issue may also arise when we try to run parallel execution on the selenium grid. Just in case we are calling driver.quit() before any other test, the driver is set to null and the subsequent test does not get the proper driver information to work on it.

We need to implement @AfterTest or @AfterGroup annotation and define the teardown method there.
We need to look for driver.close() or driver.quit() method of our code.

We are calling driver.close(). This will close the present window. On the off chance that no open windows remain, the driver stops. Thus, when our tearDown calls the driver.quit() the meeting has finished and you get a mistake.

Arrangements you could utilize:

try not to call driver.close() in our test and let the teardown handle it

or on the other hand

in the teardown, check for a legitimate session and just call driver.quit() in the event that one exists. NoSuchSessionException in selenium can occur due to this.

Step-3: Is there a Tabbing issue?

This issue can arise when we try to open a new window instead of Tab under a driver. Make sure the Tab is opened under the driver, not a new Window. New Window may need a new Session. We need to make sure we are not opening multiple browsers during testing. NoSuchSessionException in selenium can occur due to this.

Step-4: is the Browser not ready for doing operations?

This issue can also appear if we have started testing i.e @Test before even browser launches properly. If the test starts running before a successful handshake between browser and driver, the session info is invalid. We need to give enough sync time between browser launch in the @before annotation or wherever we are trying to open a browser. NoSuchSessionException in selenium can occur due to this.

See also  Constant Concept Simplified in Java

Step-5: Is Docker YML configured properly?

If we are using docker, we need to configure the docker-compose.yml file. The default size is 64MM and the recommended size is 256MB. We need to increase it. We need to check for container privilege as well. We need to execute docker with docker run –privileged mode. This flag enables all capabilities for a container. NoSuchSessionException in selenium can occur due to this.

Step-6: is there an Issue in Xpath?

Very surprisingly there could be an exception due to the way we are identifying the element. If there is an error in Xpath, id or CSS or the way, we are identifying the element, this exception can occur. We need to double-check the element finding strategy. NoSuchSessionException in selenium can occur due to this.

Step-7: Is our dependency ready?

Is our dependency file(POM.xml) correct? and is it rightly pointing to the correct artifacts like jars? We need to check this one also while working with Jenkins. NoSuchSessionException in selenium can occur due to this.

Step-8: Are we pointing the correct driver?

Are we pointing the correct driver? It may so happen that instead of pointing to the local driver we are pointing to Remote driver. The driver provides the necessary hooks to work with the browser. So it is extremely important to install and point to the correct drivers. NoSuchSessionException in selenium can occur due to this. We need to use:

Driver driver=new ChromeDriver();
//instead of 
Driver driver=new RemoteChromeDriver();
Driver driver=new RemoteWebDriver();

Step-9: Is the proxy configuration correct?

In the case of Katalon, the incorrect proxy configuration can break the code and throw this exception. The default proxy option for Katalon studio is No Proxy. Either we need to change the proxy to our desired one by navigating Run->Katalon Studio Preferences->Katalon->Proxy and change to your desired one.

See also  Class ServerSocket in Java

or we can select Use System Configuration. This will enable the browser and driver to have a proper handshake. NoSuchSessionException in selenium can occur due to this.

Step-10: Are we importing the correct package?

Importing incorrect packages may create issues. Say our chrome driver and browser is not compatible in that case if we import upgraded or downgraded package, this issue will occur. NoSuchSessionException in selenium can occur due to this.

The below imports needs our attention:

import org.openqa.selenium.WebDriver;

Apart from these also check the java version. The java and driver compatibility also plays a crucial role.

  • Overhaul JDK to latest levels JDK
  • Clean your Project Workspace through your IDE and Rebuild your project with the required conditions as it were.
  • On the off chance that your base Web Client adaptation is excessively old, at that point uninstall it and introduce an ongoing GA and discharged rendition of Web Client.
  • Take a System Reboot.
  • Execute your @Test.

What are the other exceptions that can be resolved with this approach?

The below written exceptions can also be resolved by using this post

  • org.openqa.selenium.nosuchsessionexception firefox
  • org.openqa.selenium.nosuchsessionexception: invalid session id
  • org.openqa.selenium.nosuchsessionexception session id is null
  • no such session exception in selenium
  • exception in thread main org openqa selenium nosuchsessionexception session id is null
  • org.openqa.selenium.nosuchsessionexception: invalid session id in selenium
  • org.openqa.selenium.nosuchsessionexception: tried to run command without establishing a connection
  • exception in thread “main” org.openqa.selenium.nosuchsessionexception: invalid session id

Share and Enjoy !

80 thoughts on “How to Resolve NoSuchSessionException in selenium free?

  1. I think this is among the most vital info for me. And i am glad reading your article. But want to remark on some general things, The site style is great, the articles is really excellent : D. Good job, cheers

  2. I think other site proprietors should take this website as an model, very clean and fantastic user friendly style and design, as well as the content. You’re an expert in this topic!

  3. Excellent goods from you, man. I’ve understand your stuff previous to and you’re just extremely magnificent. I actually like what you have acquired here, really like what you’re saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I can not wait to read far more from you. This is really a tremendous web site.

  4. Pingback: Google
  5. Nice post. I used to be checking constantly this blog and I am inspired! Extremely useful information specially the final section 🙂 I handle such information a lot. I used to be seeking this certain information for a very lengthy time. Thanks and best of luck.

  6. Super-Duper website! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.

  7. I haven’t checked in here for some time as I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  8. I truly wanted to jot down a simple message to be able to appreciate you for all of the wonderful recommendations you are giving out on this site. My particularly long internet lookup has at the end been honored with wonderful suggestions to talk about with my great friends. I ‘d express that we site visitors are very lucky to exist in a magnificent site with very many awesome individuals with valuable things. I feel quite grateful to have discovered your entire webpage and look forward to really more pleasurable moments reading here. Thanks a lot again for everything.

  9. Hey would you mind letting me know which hosting company you’re working with? I’ve loaded your blog in 3 completely different web browsers and I must say this blog loads a lot quicker then most. Can you suggest a good hosting provider at a fair price? Many thanks, I appreciate it!

  10. I was wondering if you ever considered changing the layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two pictures. Maybe you could space it out better?

  11. I appreciate, cause I found exactly what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a nice day. Bye

  12. Once I originally commented I clicked the -Notify me when new comments are added- checkbox and now every time a remark is added I get 4 emails with the same comment. Is there any approach you may remove me from that service? Thanks!

  13. Hey There. I discovered your blog the use of msn. This is an extremely smartly written article. I will be sure to bookmark it and come back to read extra of your helpful information. Thanks for the post. I will certainly comeback.

  14. You really make it appear really easy along with your presentation however I to find this matter to be really one thing which I think I would never understand. It kind of feels too complicated and very large for me. I’m having a look forward to your next publish, I’ll attempt to get the hang of it!

  15. What’s Taking place i’m new to this, I stumbled upon this I’ve discovered It absolutely useful and it has aided me out loads. I’m hoping to contribute & assist other customers like its helped me. Good job.

  16. F*ckin’ awesome things here. I’m very glad to see your post. Thanks a lot and i’m looking forward to contact you. Will you kindly drop me a mail?

  17. I think this is one of the most vital information for me. And i am glad reading your article. But want to remark on some general things, The website style is ideal, the articles is really excellent : D. Good job, cheers

  18. Pingback: Google
  19. Pingback: Google
  20. you are really a good webmaster. The website loading speed is incredible. It seems that you’re doing any unique trick. Furthermore, The contents are masterwork. you’ve done a great job on this topic!

  21. Thank you for the sensible critique. Me & my neighbor were just preparing to do some research on this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such great information being shared freely out there.

Leave a Reply

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