How to fix org.openqa.selenium.WebDriverException: newSession

I was using simple code to start the webdriver:

FirefoxOptions option = null;

option = new FirefoxOptions();

option.setHeadless(true);

System.out.println(“>>>>>>>> before driver”);

driver = new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub") , option);

System.out.println(“>>>>>>> after driver”);

This gave me webdriverexception — newSession.

I got help from selenium irc — thankfully.

Here is how i managed to debug:

First , I was running selenium grid, node as services with systemd with SUDO.
so, i stopped these services.

I then started hub and node without using sudo.

java -jar selenium-server-standalone-3.13.0.jar -role hub

java -Dwebdriver.gecko.driver=”/home/user/geckodriver” -jar selenium-server-standalone-3.13.0.jar -role node -maxSession 10 -browser “browserName=firefox,maxInstances=10” -hub http://localhost:4444/wd/hub maxSession 5 -browser “browserName=firefox,maxInstances=3

I saw better logs without sudo.

in the logs of node I saw this error:

Marionette  TRACE   0 <- [1,1,{"error":"unknown command","message":"newSession","stacktrace":"WebDriverError@chrome://marionette/content/error.js:178: ... et@chrome://marionette/content/server.js:245:8\n_onJSONObjectReady/<@chrome://marionette/content/transport.js:490:9\n"},null]

I googled this and found —
https://stackoverflow.com/questions/52997403/firefox-profile-is-throwing-a-selenium-webdriverexception-since-i-updated-to-fir/52998532#comment92941484_52998532

Firefox got automatically updated on my ubuntu server.

So as per this link , i updated geckodriver and got the fix.

To stop firefox from automatically updating , i used —
sudo apt-mark hold firefox

now to run systemctl without sudo
https://serverfault.com/questions/841099/systemd-grant-an-unprivileged-user-permission-to-alter-one-specific-service
remove USER = ubuntu , add default.target

Programmer and Entrepreneur.