How To Install Selenium Firefox On Centos
We will go through following three steps
- Install Firefox
- Install Selenium
- Install geckodriver
How to install Firefox on Centos
Lets check the version of Centos first...
cat /etc/os-release | egrep -i 'CPE_NAME' CPE_NAME="cpe:/o:centos:centos:7"
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.
How to install Python Selenium
pip install selenium
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
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 and Selenium
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.