Error encountered: WebDriver session not found while using ChromeDriver with Selenium and Jasmine

Currently, I am working on creating an automated test for my website using a combination of Jasmine and selenium.

However, when I run the tests on chrome with chromedriver, I encounter the error below randomly. This issue occurs frequently enough that it significantly delays the completion of my test suite.

I have come across references to this bug, but unfortunately, I haven't been able to find a definitive solution: https://bugs.chromium.org/p/chromedriver/issues/detail?id=732 (although this was specifically for chromium and not chrome)

WebDriverError: no such session
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.5 x86_64)
    at WebDriverError (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/error.js:27:10)
    at Object.checkLegacyResponse (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/error.js:639:15)
    at parseHttpResponse (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/http/index.js:538:13)
    at /Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/http/index.js:472:11
    at ManagedPromise.invokeCallback_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:1379:14)
    at TaskQueue.execute_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2913:14)
    at TaskQueue.executeNext_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2896:21)
    at /Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2820:25
    at /Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (node.js:369:9)
From: Task: WebElement.isDisplayed()
    at Driver.schedule (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/webdriver.js:377:17)
    at WebElement.schedule_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/webdriver.js:1744:25)
    at WebElement.isDisplayed (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/webdriver.js:2110:17)
    at driver.findElements.then.error (/Users/XXXXXXX/Documents/sweetmeeting/Test/front_end_testing/spec/dashboard_tester.js:251:34)
    at ManagedPromise.invokeCallback_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:1379:14)
    at TaskQueue.execute_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2913:14)
    at TaskQueue.executeNext_ (/Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2896:21)
    at /Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:2775:27
    at /Users/XXXXXXX/Documents/sweetmeeting/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (node.js:369:9)

Answer №1

After battling with this problem for quite some time, we finally found a solution that worked for us. Hoping to share our success story here in case it can benefit others.

It turns out the root of our issue was memory-related. Our testing environment runs within a docker container, and we discovered that the default dev/shm size in Docker is only 64mb. Increasing this allocation solved the pesky "no such session" error for us.

We utilize docker compose for our setup, so we simply modified the docker-compose.yml file by adding shm_size: 256M to address the problem.

Answer №2

Recently, I came across a similar exception as well. Initially, it seemed to be unpredictable, but upon closer examination, I discovered that it occurs consistently when ChromeDriver.Close() is called before attempting to FindElement.

In my scenario, the ChromeDriver.Close() method was invoked in an exception handler of a previous test due to a timing issue. This issue only impacted the subsequent test, giving the impression that it was unreliable. However, thorough investigation confirmed its deterministic nature.

Based on my findings, this is how I encountered and resolved the error. It's possible that your situation may differ...

Answer №3

This particular error message...

WebDriverError: no session found
  (Details: chromedriver=a.b.c (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.5 x86_64)

...suggests that the ChromeDriver encountered difficulties while communicating with the established Browsing Context, specifically the Chrome Browser session.


We have thoroughly discussed and analyzed this issue in the ongoing conversation Issue 732: No such session error - inconsistent problem occurring during prolonged test runs. Typically, this error manifests after an extended period of running the Test Suite as shown below:

[0127/105308:ERROR:nacl_helper_linux.cc(289)] NaCl helper process is running without a sandbox!
Likely due to incorrect SUID sandbox configuration.
[489.849][INFO]: RESPONSE FindElements unknown error: session deleted because of page crash
from tab crashed
  (Session info: chrome=p.q.r.s)
[489.849][DEBUG]: Log type 'driver' lost 0 entries upon destruction
[489.849][DEBUG]: Log type 'browser' lost 9 entries upon destruction

The definition of this error can be found in nacl_helper_linux.cc:

// If Zygote has started handling requests, we should be sandboxed via
// the setuid sandbox.
if (!IsSandboxed()) {
  LOG(ERROR) << "NaCl helper process is running without a sandbox!\n"
    << "Most likely you need to configure your SUID sandbox "
    << "correctly";

The method FindElement(s) specifically FAILED due to a sandbox issue leading to a Page Crash caused by session deletion.


Solution

This error could be triggered by various reasons, and potential solutions include:

  • To resolve this error, initiate the Chrome session by configuring the ChromeDriver with the argument --disable-impl-side-painting
    • In addition, consider adding the argument --enable-gpu-rasterization which allows heuristics to determine when a layer tile should be drawn using the Skia GPU backend. This is valid only with GPU accelerated compositing + impl-side painting.
    • You may also consider adding the argument --force-gpu-rasterization which always utilizes the Skia GPU backend for drawing layer tiles. Valid only with GPU accelerated compositing + impl-side painting. Overrides the kEnableGpuRasterization flag.
  • This error might also occur if the server fails to recognize the unique session identifier. This usually happens when the session has been deleted or if the session ID is invalid due to either of the following reasons:

    • Explicit session deletion: A WebDriver session is explicitly terminated when invoking the quit() method as shown:

      from selenium import webdriver
      from selenium.common.exceptions import InvalidSessionIdException
      
      driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      print("Current session is {}".format(driver.session_id))
      driver.quit()
      try:
          driver.get("https://www.google.com/")
      except Exception as e:
          print(e.message)
      
      #Console Output:
      Current session is a9272550-c4e5-450f-883d-553d337eed48
      No active session with ID a9272550-c4e5-450f-883d-553d337eed48
      
    • Implicit session deletion: A WebDriver session is implicitly ended when closing the last window or tab using the close() method as demonstrated:

      driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      print("Current session is {}".format(driver.session_id))
      # closes current window/tab
      driver.close()
      try:
          driver.get("https://www.google.com/")
      except Exception as e:
          print(e.message)
      
      #Console Output:
      Current session is a9272550-c4e5-450f-883d-553d337eed48
      No active session with ID a9272550-c4e5-450f-883d-553d337eed48
      
  • You might need to include the argument --no-sandbox

  • Chrome often crashes within Docker containers on certain pages due to insufficient space in /dev/shm. To fix this issue, ensure proper sizing of /dev/shm.
  • One possible solution:

    sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    
  • Alternatively, use the -v /dev/shm:/dev/shm option to share the host /dev/shm

  • An additional approach would be to add chrome_options with --disable-dev-shm-usage. This forces Chrome to utilize the /tmp directory instead. Note that this may slow down execution since disk storage will be utilized rather than memory.

    chrome_options.add_argument('--disable-dev-shm-usage')        
    

Reference

For further insights, refer to these detailed discussions:

  • selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python
  • unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed with ChromeDriver Selenium
  • org.openqa.selenium.SessionNotCreatedException: session not created exception from tab crashed error when executing from Jenkins CI server

Answer №4

At times, we tend to overcomplicate things by delving too deep into a problem's complexity, when the solution may actually be quite simple and straightforward.

I encountered this issue while using browser.close() as an exception handler in my logout() method. This action ended the session, causing subsequent protractor tests to fail with an error.

By removing browser.close() and opting to throw an error instead, I was able to successfully resolve the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for effectively combining Selenium and Scrapy in your web scraping projects

Struggling to access Bloomberg for scraping the title and date, I turned to a headless browser to get the required data. Here's the code snippet using both Selenium and Scrapy: import scrapy from selenium import webdriver from selenium.webdriver.sup ...

Is it possible for a Python and R file to collaborate and share a single webdriver session?

I've been working on a web scraper using RSelenium, but have found that certain tasks are better suited for Python. To streamline this process, I've created a .Rmd file with code snippets in both R and Python. The RSelenium side of the project i ...

Extracting data from websites using Python's Selenium module, focusing on dynamic links generated through Javascript

Currently, I am in the process of developing a webcrawler using Selenium and Python. However, I have encountered an issue that needs to be addressed. The crawler functions by identifying all links with ListlinkerHref = self.browser.find_elements_by_xpath( ...

Auto-complete feature not populating the input field in Google Chrome

Within my register form, I have various INPUT tags present. One of these INPUTs has the name email. <input type=text name=email id=email> When filling out this form in Chrome, I encounter a peculiar behavior. Upon clicking on the email input field ...

Having difficulty saving data in database using Ajax request from a Chrome extension

I am currently working on an extension that captures the page URL and saves it in a database once the user clicks the submit button. However, I have encountered a roadblock and believe there might be a missing piece in the extension setup that I cannot pi ...

A combination of Tor Browser, Selenium, and Javascript for

I have been attempting to use selenium with Tor, but unfortunately it is not functioning correctly. I have come across a library that allows for this functionality, however, it appears to only work with Python. Is there a way to accomplish this using Jav ...

Using selenium, you can easily download a file without needing the direct URL

I need assistance with using Selenium for website automation in Chrome using vb.net. I am trying to download files from a website that does not have direct URLs for download buttons, as the downloads are triggered by JavaScript. How can I accomplish this i ...

Set up the RefControl extension with the help of the Selenium WebDriver

I have successfully implemented this addon with selenium. However, I am unsure how to adjust the settings of addons in selenium. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile from selenium.webdriver.firefox import webdriver profil ...

What are the steps for installing modules and packages on Linux without an internet connection?

Is there a way to install the modules and packages listed below offline in Linux? import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.rem ...

Is it possible to navigate to an iframe within an iframe after resetting to defaultContent()?

Why does my webdriver throw an exception when I try to switch to a frame(2) inside a frame(1) after using driver.switchTo.defaultContent()? Removing this line allows me to find the frame(2). Can someone clarify why this behavior occurs? driver.switchTo().d ...

Performing unit testing on two services that reside in separate modules using the Jasmine testing framework

I have developed a service in Angular and you can view it on this PLUNKER. In the RouteService, I am injecting CommonService, $rootRouter, ModalService. Please note the following module structure : CommonService belongs to mysampleapp.core RouteS ...

Is there a method to automatically switch proxies every 5 minutes using a browser extension?

Looking to implement a proxy switcher in Selenium using Python. Currently, I have code that adds a proxy through an extension but now I need to modify it to switch proxies multiple times. The goal is to create a "Proxy Switcher" extension. manifest_json ...

Obtaining the console.log data from Chrome using the Selenium Python API bindings

Currently, I am utilizing Selenium to conduct tests in Chrome through the Python API bindings. I am facing difficulties when it comes to configuring Chrome in order to access the console.log output from the executed test. While exploring the WebDriver ob ...

The npm script for running Protractor is encountering an error

Currently, I am facing an issue while trying to execute the conf.js file using an npm script. The conf.js file is generated within the JSFilesRepo/config folder after running the tsc command as I am utilizing TypeScript in conjunction with protractor-jasmi ...

Using Selenium XPath to select an element based on the text that follows a specific comment

I came across this HTML snippet: <div> <!-- \/ this div --> <div> aaa <!-- --> bbb </div> </div> I attempted to select the second div using "//div[contains(text(), 'bbb&apo ...

What are some strategies for bypassing a Proxy server in Selenium WebDriver?

My system is set up with a proxy server, but when I use selenium web driver to open a URL, the browser launches without passing the URL in the address bar. How can I work around this issue with the proxy server setup? I have attempted the following code ...

Finding a nested div within another div using text that is not tagged with XPath

I need help creating an XPath to select a div with the class "membername" using the parameter "Laura". <div class="label"> <div class="membername"></div> David </div> <div class="label"> < ...

Pause until an email is received in Selenium

I am working on a code snippet to check for emails after a form submission. Sometimes, there is a delay in receiving the email. I have implemented a thread.sleep for 20 seconds before calling the email method, but it seems insufficient. Is there any way ...

What is the best way to set up a full class in C# using the PageObject design pattern?

Since the pageFactory is now deprecated in C#, I am curious about how to properly initialize classes in C#. I attempted to use @Findby to call them in the Testcase, but it resulted in a large number of objects being written. Is there a more efficient way? ...

Incomplete roster of kids using Selenium in Python

Does anyone have a solution for retrieving all the children of an element in HTML? Here is the structure of the html: Check out this image of the html structure I've tried the following code: time.sleep(30) stocks = browser.find_element_by_class_na ...