How To Install Selenium Chrome On Centos 7
Installing Chrome and Selenium can be quite challenging. This post goes through step by step tutorial to install Selenium and Chrome. I have also put together a small section at the end to cover "most commonly errors" during installation. Lets get started now.
Lets install first Chrome.
How to install Chrome On Centos 7
Lets install chrome now.
yum localinstall google-chrome-stable_current_x86_64.rpm
Lets check if chrome is installed.
google-chrome --version Google Chrome 79.0.3945.130
I will be using Python Selenium for this post.
How to install Python Selenium
Lets install Selenium first using pip.
pip install selenium Collecting selenium Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Requirement already satisfied: urllib3 in /home/anaconda3/lib/python3.7/site-packages (from selenium) (1.24.2) Installing collected packages: selenium Successfully installed selenium-3.141.0
We also need to install package chromedriver. Install it using yum.
yum install chromedriver
Lets try using the Selenium now in Ipython. Import following packages in ipython.
from selenium import webdriver
I am running Chrome as headless on Centos. So we need to add following options before initializing the webdriver.
chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("--headless") chromeOptions.add_argument("--remote-debugging-port=9222") chromeOptions.add_argument('--no-sandbox')
Lets initialize Chrome webdriver now.
self.driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chromeOptions)
Commonly encountered errors while intializing Chrome webdriver
Please do following if you encounter any one of the following errors while initializing chrome webdriver.
If you got following error. It means either your chrome installation is not done or not correct. Check it and make sure it is installed correctly.
WebDriverException: Message: unknown error: cannot find Chrome binary
If you get following. Make sure --headless option is added.
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
To fix following error. Make sure --remote-debugging-port option is added.
unknown error: DevToolsActivePort file doesn't exist
To fix following error, make sure --no-sandbox option is added as shown above.
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (chrome not reachable)