38

I am trying to get the Selenium server up and running. However, when I type:

java -jar selenium-server-standalone-2.0b3.jar

I get an Exception:

Selenium is already running on port 4444. Or some other service is.

I have tried to stop it, just in case it really is running:

http://localhost:4444/selenium-server/driver/?cmd=shutDown

That gets me the message:

ERROR Server Exception: sessionId should not be null; has this session been started yet?

If I just write:

http://localhost:4444/

I get:

HTTP ERROR: 403
Forbidden for Proxy

Ideas?

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
dkgirl
  • 3,679
  • 7
  • 22
  • 25

15 Answers15

46

This worked for me:

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

If selenium server is already running on port 4444 then it will shut down the server and says OKOK if selenium is not running on this port 4444 then by hitting above url will give you "Unable to connect"

Andre
  • 2,359
  • 22
  • 23
  • It does not work. It redirects to selenium server page, saying Whoops! The URL specified routes to this help page. For more information about Selenium Standalone please see the docs and/or visit the wiki. Or perhaps you are looking for the Selenium Standalone console. Happy Testing! – Ayush Aug 31 '17 at 07:21
20

try this:

lsof -i -n -P | grep 4444

and kill the process it says is on :4444

HaloWebMaster
  • 882
  • 6
  • 16
17

One-liner:

kill -9 $(lsof -ti tcp:4444)

  • A fine answer if you are sure your selenium is running on port 4444. I gave an alternate solution for people wanting to kill selenium started via java which is not port dependent, although it has its own caveats http://stackoverflow.com/a/42143391/3249501 – GrayedFox Feb 09 '17 at 17:43
9

The error message Selenium offers up is a little confusing. It really should be telling you you're making a syntax error. I had this problem as well. Make sure the cmd string is PRECISELY like this:

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

That means using the full command shutDownSeleniumServer, and make sure the s in shut is lower-case (That was my mistake).

Hope this helps.

Greg Gauthier
  • 1,017
  • 1
  • 9
  • 24
7

To shut down the server you can use: http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

It will give message OKOK , means it got shutdown. If the server is not running then it will show "This web page not available"

To check the selenium server status , use this http://localhost:4444/selenium-server/driver/?cmd=getLogMessages

It will give OK if server is running , if not running then it will show webpage not available

Juhi Saxena
  • 1,077
  • 11
  • 16
5

If you are using Windows, you can open the task manager and locate the java.exe or javaw.exe process and kill it. This will release port 4444 and you should be able to restart the Selenium server.

dex1304
  • 154
  • 2
4

I had the same error but no server was running. Tuned out the java version was in cause. Make sure you are running java 7 or higher:

java -version
A21z
  • 759
  • 7
  • 17
  • Same here. On OSX El Capitan, the default JDK 1.6 isn't high enough for Selenium standalone to function properly. Updating with "brew cask install java" resolved the issue for me by installing JDK 1.8 side-by-side with the already-installed 1.6 version. – Crates Jul 25 '16 at 15:03
1

lsof returned no results in my case.

On a Ubuntu machine I had to do the following:

sudo netstat -tapen | grep ":4444 "

Reply was like:

tcp6       0      0 XXXXXXXXX:4444       :::*                    LISTEN      107        31526       **10479**/java

And to kill the Selenium server process identified (in my case) with 10479

sudo kill 10479
Valentin Despa
  • 34,200
  • 18
  • 76
  • 100
1

In OSX if you follow the command from @HaloWebMaster (lsof -i -n -P | grep 4444) the next step is to take the PID (usually a 4 - 5 digit number indicating the process ID) and run the following command:

kill -9 <PID>

You shouldn't need sudo unless the process was started by another user or root.

jfunk
  • 3,257
  • 2
  • 26
  • 31
1

If you started Selenium using Java (instead of via whatever testing framework you may or may not be using), you can kill all leftover Selenium instances with:

pkill java

That's guaranteed to kill any java relics (including selenium if started this way) - but be careful here - caveat is that you might be killing other procs too (due to the way pkill works). In my case, I want to kill anything running in the JVM, so this solved it for me.

As per the comment from Goldberg below, note that this will not kill any driver services or browsers running on your system!

GrayedFox
  • 1,524
  • 21
  • 37
  • 1
    this won't kill a spawned driver service like chromedriver or geckodriver.. it also won't kill the browser. It just kills all instances of java, leaving orphaned browsers and driver services behind – Corey Goldberg Jun 16 '18 at 16:35
  • That is true, but my understanding is that the OP's problem is that they have left over Selenium instances running (and not leftover chrome/gecko/web driver instances or browsers open), and since Selenium must necessarily be inside the JVM, this answer merely suggests a method to kill that process (with the caveat that it would also kill any other Java instance if using pkill). Will update the post to reflect your comment however :) – GrayedFox Jun 18 '18 at 08:05
1

I had the same problem , I started my Jboss AP where i have my application deployed and after that tried to run the selenium server and couldn t start. The problem was that Jboss uses the same port that Selenium server uses, so what I did is to start selenium server on a different port

Solution:

java -jar selenium-server-standalone-2.0b3.jar -port 1234 -htmlSuite "*firefox" "http://localhost:8080/" "path to the suite" "path to the results"
frianH
  • 5,901
  • 6
  • 13
  • 36
Roberto
  • 11
  • 2
0

Thanks,

The link of Andre works fine for me.

As 4444 is the default port of Selenium check this as well.

0

If you get a 403 error on 127.0.01:4444 and not a 404 one, something is running there. (You're positive it cannot be a previous instance Selenium ? It'd be the most logical.)

Sometimes Selenium continue running in the background after an unexpected exit. I'd suggest checking the running processes, or rebooting the machine if everything else fails.

It happens to me frequently when Hudson asks Selenium-Server to run some tests and it fails in the middle for some reasons. Killing the process solves the problem.

Silver Quettier
  • 1,893
  • 1
  • 22
  • 47
0

That ERROR Server Exception: sessionId should not be null; has this session been started yet? message comes from Selenium. If you're seeing it, there's a Selenium server running on that port number.

Ross Patterson
  • 9,233
  • 30
  • 47
0

If all the above is not working, please save your work and reboot your system. It will solve the problem

Bhavana
  • 95
  • 3
  • 5
  • 2
    This is a pretty awful workaround and impossible if running selenium in some sort of CI env, not to mention completely unscalable (what happens if you get this error 10 times a day? 10 reboots?) I think you can do better ;) – GrayedFox Feb 09 '17 at 17:41