How To Install Selenium Firefox On Centos

Last updated: 2019-05-19

We will go through following three steps

  1. Install Firefox
  2. Install Selenium
  3. Install geckodriver

How to install Firefox on Centos

Lets check the version of Centos first...

cat /etc/os-release | egrep -i 'CPE_NAME'

Lets check our platform too...

uname -a
Linux ns532310 4.19-ovh-xxxx-std-ipv6-64 #1038749 SMP Mon Dec 23 08:31:48 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Given that Lets now install Firefox using yum.

yum -y install firefox

Above will install Firefox.

Install Xvfb

yum install Xvfb

How to install Python Selenium

pip install selenium

pip install pyvirtualdisplay

How to install Firefox geckodriver

Lastly we need geckodriver, the driver through which Selenium will access Firefox.

Go to following link and get the latest tar.gz file based on your operating system.


We need to untar it.

tar -xf geckodriver-v0.26.0-linux64.tar.gz
mv geckodriver /usr/local/bin/

How to use Selenium with Firefox

Invoke ipython

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver',options=options)

If you didn't get any error, it means everything just worked fine.

Common errors while installing Firefox, Selenium and Xvfb

If you got following error, it means you are missing options.headless = True

WebDriverException: Message: invalid argument: can't kill an exited process

If you got following error, it means geckodriver is not installed properly

WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

If you see following error, it means Xvfb is not installed properly, Make sure yum install Xvfb has gone through successfully.

EasyProcessError: start error <EasyProcess cmd_param=['Xvfb', '-help'] cmd=['Xvfb', '-help'] oserror=[Errno 2] No such file or directory: 'Xvfb': 'Xvfb' return_code=None stdout="None" stderr="None" timeout_happened=False>

If you see following error, it is coming from inside pyvirtualdisplay. I couldn't find any solution for this error, good thing is that this error can be ignored.

xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!