Home > front end >  SessionNotCreatedException: Could not start a new session. Response code 500 error using Selenium Ja
SessionNotCreatedException: Could not start a new session. Response code 500 error using Selenium Ja

Time:07-27

I want to test my script on chrome beta version and for that reason I have installed chrome beta version but somehow I am not able to start it using Selenium Java. I have all the needed dependency added in pom.xml file regarding webdriver manager etc. I am sharing my console error and also script.

ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\Users\\WRP\\Downloads\\Programs\\ChromeSetup.exe");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(optionsBeta);
//System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver.exe");
//  WebDriver driver = new ChromeDriver();
WebDriverManager.chromedriver().setup();
//WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
//WebDriver driver = new ChromeDriver();
WebDriverWait waits=new WebDriverWait (driver, Duration.ofSeconds(10));

Error tracelogs:

Starting ChromeDriver 104.0.5112.29 (eff877e18f767c77fef0481a1cba402c8cbad404-refs/branch-heads/5112@{#422}) on port 55215
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'AWAIS-PC', ip: '192.168.1.62', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., extensions: []}}}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:264)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:179)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:70)
    at First_Test.Practice_First.main(Practice_First.java:29)

CodePudding user response:

This error message...

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. session.

Your have to take care of a couple of things here as follows:

  • setBinary() argument should be used to point to the binary executable i.e. chrome.exe post installation of the browser software (ChromeSetup.exe)

    optionsBeta.setBinary("C:\\location\\to\\chrome.exe");
    
  • You'd use either of the following (not both):

    • The downloaded version of the chromedriver.exe using the System.setProperty() line as follows:

      System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
      
    • The WebDriverManager dependency in pom.xml and setup the chromedriver as:

      WebDriverManager.chromedriver().setup();
      

Your effective code block will be:

  • Using downloaded ChromeDriver:

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
    ChromeOptions optionsBeta = new ChromeOptions();
    optionsBeta.setBinary("C:\\location\\to\\chrome.exe");      
    WebDriver driver = new ChromeDriver(optionsBeta);
    
  • Using Maven Dependency in pom.xml:

    WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
    ChromeOptions optionsBeta = new ChromeOptions();
    optionsBeta.setBinary("C:\\location\\to\\chrome.exe");      
    WebDriver driver = new ChromeDriver(optionsBeta);
    
  • Related