Response code 404. Message: Unable to find handler for (POST) /session

1,019 views
Skip to first unread message

Darin Duphorn

unread,
May 17, 2023, 5:15:33 PM5/17/23
to Selenium Users
I manually started my hub and node and verified they are both up.

java -jar selenium-server-4.9.0.jar hub --port 4444

java -jar selenium-server-4.9.0.jar node --hub http://localhost:4444/grid/register --port 6666 


The hub and node correctly display correctly when I put this in the browser: http://localhost:4444/ui

Selenium
<dependency>
<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>4.0.0-alpha-2</version> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.9.0</version> </dependency>

Below is the code
try {
     // Set the URL of the Selenium Node
     String hubUrl = "http://127.0.0.1:6666";
   ChromeOptions browserOptions = new ChromeOptions();
     browserOptions.setPlatformName("MAC");
     browserOptions.setBrowserVersion("113");
           
     // Create a remote WebDriver instance
     threadDriver.set(new RemoteWebDriver(new URL(hubUrl), browserOptions));
 } catch (Exception e) {
     e.printStackTrace();
 }

When I step through this
 threadDriver.set(new RemoteWebDriver(new URL(hubUrl), browserOptions));

It fails to generate a new Session here

protected void startSession(Capabilities capabilities) {
    checkNonW3CCapabilities(capabilities);
    checkChromeW3CFalse(capabilities);

    Response response = execute(DriverCommand.NEW_SESSION(singleton(capabilities)));

And I'm not sure why?   Any ideas?

Thanks

Darin

Krishnan Mahadevan

unread,
May 17, 2023, 8:58:06 PM5/17/23
to seleniu...@googlegroups.com
You should be targetting the hub in your code ( 4444 port and not 6666 )

A new session can be created only via hub or via standalone. I dont think you can hit the node directly and expect a session to be created ( for that the url is different which only a hub or a standalone knows ) 

Also please use the latest version ( i think now its 4.9.3 maybe)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Darin Duphorn <neversto...@gmail.com>
Sent: Thursday, May 18, 2023 2:45:33 AM
To: Selenium Users <seleniu...@googlegroups.com>
Subject: [selenium-users] Response code 404. Message: Unable to find handler for (POST) /session
 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f2c24449-1336-43f7-8231-df42f3b8d2fcn%40googlegroups.com.

Darin Duphorn

unread,
May 18, 2023, 11:25:57 AM5/18/23
to Selenium Users
I tried both 4444 and 6666.  

When I was running in selenium-server 3.141.59 I used the below code with success.

threadDriver.set(new RemoteWebDriver(new URL("http://localhost:6666/wd/hub"), chromeoptions));

Now when I used 4444 I get this

May 18, 2023 10:17:49 AM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer

INFO: Using OpenTelemetry for tracing

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 


When I use 6666 I get this

May 18, 2023 10:23:36 AM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer

INFO: Using OpenTelemetry for tracing

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: Unable to find handler for (POST) /session 


I will update to 4.9.3 and update you after that.


Thanks for getting back to me.


DD

Darin Duphorn

unread,
May 18, 2023, 11:40:17 AM5/18/23
to Selenium Users
I was able to update to 4.9.1 instead of 4.9.3 and I received the same errors.

Darin Duphorn

unread,
May 18, 2023, 2:36:11 PM5/18/23
to Selenium Users

//This works

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);

WebDriver driver = new ChromeDriver(chromeOptions);

//This Fails

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);

RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL("http://www.example.com"), chromeOptions);



Error


ay 18, 2023 1:30:20 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer

INFO: Using OpenTelemetry for tracing

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response: <?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>404 - Not Found</title>

</head>

<body>

<h1>404 - Not Found</h1>

<script type="text/javascript" src="//obj.ac.bcon.ecdns.net/ec_tpm_bcon.js"></script>

</body>

</html>


T

Darin Duphorn

unread,
May 18, 2023, 4:55:08 PM5/18/23
to Selenium Users

Case closed I got it to work


switch (strBrowser) { case "Chrome": try { //This works ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL); if (strHeadless.equals("True")) {chromeOptions.addArguments("--headless");} WebDriver driver = new ChromeDriver(chromeOptions); RemoteWebDriver remoteDriver = (RemoteWebDriver) driver; ThreadLocal<RemoteWebDriver> threadDriver = new ThreadLocal<>(); threadDriver.set(remoteDriver); return threadDriver; } catch (Exception e) { e.printStackTrace(); System.out.println("MIH"); } break; }

⇜Krishnan Mahadevan⇝

unread,
May 19, 2023, 3:25:25 AM5/19/23
to seleniu...@googlegroups.com
Darin,

I think we are going around in circles. So let me call out a few things that are obvious (please bear with me if you feel them to be repetitive)

* Use RemoteWebDriver ONLY when you want to talk to a remote execution environment (For e.g., you have a hub/node setup done on a bunch of EC2 machines running in AWS (or) you have a paid subscription with one of the SaaS providers such as BrowserStack or SauceLabs)
* The URL you provide when creating the RemoteWebDriver should always point to where your Hub is running. 

Your example shows that you are pointing the URL to some domain which explains why the test fails for your second combo.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Shivam Kumar Bhatnagar

unread,
May 22, 2023, 1:11:52 AM5/22/23
to seleniu...@googlegroups.com
Darin,
I have sent some code for you to see how it works once you launch the browser.
and make sure you can declare these things outside the method.. 

static ChromeOptions chromeOptions;
static DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
static DesiredCapabilities firefoxCapabilities = DesiredCapabilities.firefox();


System.setProperty("webdriver.chrome.driver", "./WebDriverEXE/chromedriver.exe");
chromeOptions = new ChromeOptions();
List<String> list = new ArrayList<String>();
list.add("start-maximized");
list.add("disable-infobars");
chromeOptions.addArguments(list);
chromeCapabilities = DesiredCapabilities.chrome();
chromeCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new ChromeDriver(chromeCapabilities);

Use this code to work from your end.

Shivam Kumar Bhatnagar

Test Engineer | EdServices

: www.magicedtech.com

  : +91 9027699186




"The content of this email is confidential and intended solely for the use of the individual or entity to whom they are addressed. It is strictly forbidden to share any part of this message with any third party, without the written consent of the sender. If you have received it by mistake, please inform us by an email reply and then delete the message. If you are not the intended recipient, you are notified that disclosing, copying, distributing, or taking any action in reliance on the contents of this information is strictly prohibited".
Reply all
Reply to author
Forward
0 new messages