Selenium: Invalid "already running" error when starting server
Asked Answered
M

16

39

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?

Mistletoe answered 4/5, 2011 at 12:36 Comment(0)
S
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"

Stevenson answered 15/2, 2012 at 3:27 Comment(1)
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!Riverhead
N
22

try this:

lsof -i -n -P | grep 4444

and kill the process it says is on :4444

Nardone answered 4/5, 2011 at 12:46 Comment(1)
and the kill part should be done like so kill -9 <PID>Saharan
M
18

One-liner:

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

Misfortune answered 21/6, 2016 at 10:0 Comment(1)
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 https://mcmap.net/q/399162/-selenium-invalid-quot-already-running-quot-error-when-starting-serverEngorge
G
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.

Gascony answered 14/6, 2011 at 14:57 Comment(0)
S
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

Scouting answered 5/8, 2015 at 8:17 Comment(0)
D
6

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.

Dap answered 4/5, 2011 at 19:12 Comment(1)
But I do not have these processes in the Task Manager.Edita
S
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
Seedcase answered 16/10, 2015 at 19:3 Comment(1)
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.Dichloride
E
2

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!

Engorge answered 9/2, 2017 at 17:40 Comment(2)
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 behindEncumber
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 :)Engorge
H
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"
Highsmith answered 11/5, 2011 at 19:50 Comment(0)
C
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
Caterwaul answered 15/2, 2015 at 16:59 Comment(0)
D
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.

Deponent answered 5/8, 2015 at 2:16 Comment(0)
G
1

For Windows, try this:

taskkill /PID <ProcessID> /F

Georg answered 25/8, 2022 at 11:44 Comment(0)
P
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.

Plasticine answered 4/5, 2011 at 13:25 Comment(0)
S
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.

Snowwhite answered 4/5, 2011 at 18:40 Comment(0)
C
0

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

Cozart answered 10/5, 2011 at 0:39 Comment(1)
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 ;)Engorge
W
0

Thanks,

The link of Andre works fine for me.

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

Wine answered 2/6, 2014 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.