Could not start a new session. Response code 404

Using java-client 8.4.0

  1. Started my Hub and Nodes like using this

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

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);

if (strHeadless.equals(“True”)) {
chromeOptions.addArguments("–headless=new");
chromeOptions.addArguments(“start-maximized”);
chromeOptions.addArguments(“enable-features=NetworkService,NetworkServiceInProcess”);
chromeOptions.addArguments("–no-sandbox");
chromeOptions.addArguments(“enable-precise-memory-info”);
chromeOptions.addArguments(“disable-infobars”);
chromeOptions.addArguments(“platformName”, “Chrome”);
chromeOptions.addArguments("–window-size=1920,1080");
}

String gridUrl = “http://localhost:6666/wd/hub”;
try {
URL remoteUrl = new URL(gridUrl);

	WebDriver driver = new RemoteWebDriver(remoteUrl, chromeOptions);
	} catch (Exception e) {
	      Reporter.log("<font color='red'>The Selenium Hub and Node were not started</font>");
	      Assert.fail("The Selenium Node was not started-" + gridUrl);
}

Error Message:

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

Host info: host: ‘MacBook-Pro-2.local’, ip: ‘2601:441:4901:632a:d9a5:44f0:30e8:24d2%en0’

Build info: version: ‘4.9.0’, revision: ‘d7057100a6’

System info: os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘13.3.1’, java.version: ‘1.8.0_371’

Driver info: org.openqa.selenium.remote.RemoteWebDriver

Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [headless, start-maximized, enable-features=NetworkServ…, --no-sandbox, enable-precise-memory-info, disable-infobars, platformName, Chrome, --window-size=1920,1080], extensions: []}, pageLoadStrategy: none}]}]

Capabilities {browserName: chrome, goog:chromeOptions: {args: [headless, start-maximized, enable-features=NetworkServ…, --no-sandbox, enable-precise-memory-info, disable-infobars, platformName, Chrome, --window-size=1920,1080], extensions: []}, pageLoadStrategy: none}

What am I missing?

The version of Appium you are using.
Whether this worked before or is a new install.

Those are the main things missing from this post. Adding the full log as a git gist would also be helpful.

1 Like

I’m using 2.0.0-beta.66

It was working on 1.22.3

I’m sure their and capability changes that I’m missing.

I did update the chromeOptions.addArguments("–headless=new"); and updated it above, but I’m still getting the error.

Ok, I have an answer for you.

Try changing the start code of Appium 2 server to something like:

# Start the server on the given port, host and use the base path prefix (the default prefix is /)
appium server -p 9000 -a 127.0.0.1 -pa /wd/hub

Documented here under “Server Command Line Interface”:

I’m seeing that you might use --base-path=/wd/hub:
https://appium.io/docs/en/2.0/guides/grid/

Ah.

When I run: appium server -p 4723 -a 127.0.0.1 -pa /wd/hub

I’m now getting.

[HTTP] No route found for /graphql

I ran: npm install graphql

and it installed correctly, but iI’m getting the same error.

Looking into it now.

If you installed Appium with -g (global) you may have to install dependencies that way also.

1 Like

npm -g install graphql fixed the issue and now I’m getting: POST /grid/console/session 404 13 ms - 211

I’m looking for the dependency that install this.

Should we not install appium with -g?

Oh, it’s fine. I’m just noting that there is a difference. NPM can be really confusing when something (like Appium) is installed both globally and non-globally.

I think you want Appium globally so that you can use ‘appium’ keyword to start the server.

1 Like

#1
java -jar selenium-server-4.9.0.jar standalone
java -jar selenium-server-4.9.0.jar node --port 6666

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

I doesn’t matter if I start the hub using either above, I’m still getting the same error when I attempt

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

Host info: host: ‘MacBook-Pro-2.local’, ip: ‘fe80:0:0:0:145e:6006:2d5e:77c9%en0’

Build info: version: ‘4.9.0’, revision: ‘d7057100a6’

System info: os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘13.3.1’, java.version: ‘1.8.0_371’

Driver info: org.openqa.selenium.remote.RemoteWebDriver

Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [–headless=new, start-maximized, enable-features=NetworkServ…, --no-sandbox, enable-precise-memory-info, disable-infobars, platformName, Chrome, --window-size=1920,1080], extensions: }, pageLoadStrategy: none}]}]

Capabilities {browserName: chrome, goog:chromeOptions: {args: [–headless=new, start-maximized, enable-features=NetworkServ…, --no-sandbox, enable-precise-memory-info, disable-infobars, platformName, Chrome, --window-size=1920,1080], extensions: }, pageLoadStrategy: none}

I’m miffed.

When I enter this in the browser http://localhost:4444/wd/hub

I get this which clear is the issue.

{
“value”: {
“error”: “unknown command”,
“message”: “Unable to find handler for (GET) \u002fwd\u002fhub”,
“stacktrace”: “”
}
}

I should be seeing something like this

{
“sessionId”: null,
“status”: 13,
“value”: {
“class”: “java.lang.NullPointerException”,
“error”: “unknown error”,
“message”: null,
“stackTrace”: [
{
“className”: “org.openqa.grid.internal.ExternalSessionKey”,
“fileName”: “ExternalSessionKey.java”,
“lineNumber”: 79,
“methodName”: “fromWebDriverRequest”
},
{
“className”: “org.openqa.grid.web.servlet.handler.WebDriverRequest”,
“fileName”: “WebDriverRequest.java”,
“lineNumber”: 58,
“methodName”: “extractSession”
},
{
“className”: “org.openqa.grid.web.servlet.handler.RequestHandler”,
“fileName”: “RequestHandler.java”,
“lineNumber”: 240,
“methodName”: “getSession”
},
{
“className”: “org.openqa.grid.web.servlet.handler.RequestHandler”,
“fileName”: “RequestHandler.java”,
“lineNumber”: 123,
“methodName”: “process”
},

I think you need to add the --base-path=/wd/hub to either of these.

I read somewhere that

-base-path argument is not supported in Selenium Server 4.9.0

I noticed I still had the “/wd/hub” in my path so I removed it but now I’m getting new error.

threadDriver.set(new RemoteWebDriver(new URL(strRemotePath+"/wd/hub"), chromeoptions));

Below is the updated code

CommonANDROID clsCommonMobile = new CommonANDROID ();
objDictionary.put(“strDeviceAppiumPort”, “6666”);
//clsCommonMobile.stopServer(objDictionary);
clsCommonMobile.startServer(objDictionary);

threadDriver = new ThreadLocal();
ChromeOptions chromeoptions = new ChromeOptions();
//chromeoptions.setPageLoadStrategy(PageLoadStrategy.NONE);
chromeoptions.setCapability(“browserVersion”, “113”);
chromeoptions.setCapability(“platformName”, “macOS”);
chromeoptions.setCapability(“automationName”, “uiautomator2”);
//chromeoptions.setCapability(“seleniumProtocol”, “WebDriver”);

//Load Latest Chromedriver
try {
WebDriverManager.chromedriver().setup();
} catch (Exception e) {
Reporter.log(“Error In Loading ChromeDriver”) Assert.fail(“Error In Loading ChromeDriver”);
}

//http://localhost:6666
try {
threadDriver.set(new RemoteWebDriver(new URL(strRemotePath), chromeoptions));
}
catch (Exception e) {
Reporter.log(“The Selenium Hub and Node were not started”);
Assert.fail(“The Selenium Node was not started-”+strRemotePath);}
break;

if this is enabled: chromeoptions.setCapability(“automationName”, “uiautomator2”);

I get the error:

WARNING: Support for Legacy Capabilities is deprecated; You are sending the following invalid capabilities: [automationName]; Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/

if this is disabled: chromeoptions.setCapability(“automationName”, “uiautomator2”);

I get this error
Appium]e[39m Could not parse W3C capabilities: ‘automationName’ can’t be blank

[debug] e[38;5;16m[AppiumDriver@1376]e[0m Event ‘newSessionStarted’ logged at 1684162453389 (09:54:13 GMT-0500 (Central Daylight Time))

[debug] e[38;5;16m[AppiumDriver@1376]e[0m Encountered internal error running command: InvalidArgumentError: ‘automationName’ can’t be blank

I’ve tried a few things from https://www.selenium.dev/blog/2022/legacy-protocol-support/ without sucess :frowning:

Any ideas?

What have you tried? It lists supported capabilities and says any others need a prefix, which I believe in this case is, appium:

So capabilities might look like:

Right?

I did try these

ChromeOptions chromeoptions = new ChromeOptions();
chromeoptions.setPlatformName(“MAC”);
chromeoptions.setBrowserVersion(“113”);
Map<String, Object> cloudOptions = new HashMap<>();
cloudOptions.put(“build”, “1”);
cloudOptions.put(“name”, “Test”);
chromeoptions.setCapability(“cloud:options”, cloudOptions);

But I’m getting this.

The method setPlatformName(String) is undefined for the type
ChromeOptions

The method setBrowserVersion(String) is undefined for the type
ChromeOptions

When I use what you posted I get

Multiple markers at this line

  • Syntax error on tokens, delete these tokens

  • The method setBrowserVersion() is undefined for the type
    ChromeOptions

Ok, what if you use the syntax that is working for most but just try:

chromeoptions.setCapability(“appium:automationName”, “uiautomator2”);

Same message:

May 15, 2023 11:52:19 AM org.openqa.selenium.remote.RemoteWebDriver checkNonW3CCapabilities

WARNING: Support for Legacy Capabilities is deprecated; You are sending the following invalid capabilities: [seleniumProtocol]; Please update to W3C Syntax: Removing Legacy Protocol Support | Selenium

Would there be a selenium setting that isn’t installed globally that may cause this?

I’m wondering if using ChromeOptions is part of the problem. I’m looking at this tutorial on setting up Selenium Grid for testing Chrome, and it looks very different. Can you check this and see if a setup like this might work for you?

https://appiumpro.com/editions/54-using-appium-with-selenium-grid