Running Selenium Server on Ubuntu 10.04

I decided to record the process of starting Selenium server as it was not easy to find such info on the fly.
I follow instructions of Dan Straw literally:

sudo su
mkdir /usr/lib/selenium/
cd /usr/lib/selenium/
mkdir -p /var/log/selenium/
chmod a+w /var/log/selenium/

Take this attachment, and save it as /etc/init.d/selenium
This script lets you to start, stop, restart etc. the server in a conventional to Linux environment way, by passing ‘start’, ‘stop’ arguments. Selenium server will be listening on port 4443, while default port is 4444; keep in mind when playing with examples on the web.

Add the script so that it starts automatically when the server does (don’t yet understand how this works):

update-rc.d selenium defaults

Now, to start selenium server:

/etc/init.d/selenium start

To stop:

/etc/init.d/selenium stop

To check if server is running:

sudo lsof -i :4443

Without “sudo”, it is possible that system will show that no process is listening on the port, while selenium may be running normally. This can happen if you started selenium using “sudo”.

Below is a snippet of Python code that starts server, initializes selenium client (browser), connects to the server, and stops the client:

import time, os
from selenium import selenium

def main():
  os.system("/etc/init.d/selenium start")
  # wait for server to start; otherwise can get "connection refused" error
  sel = selenium("localhost", 4443, "*firefox", "http://localhost:8000/")
  os.system("/etc/init.d/selenium stop")
if __name__ == "__main__":

This entry was posted in Bash, Python, Selenium, UNIX/Linux and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s