Skip to content

Instantly share code, notes, and snippets.

@waqashamid
Created July 11, 2020 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waqashamid/ff3f934c37fef89706bdd867431b4fcd to your computer and use it in GitHub Desktop.
Save waqashamid/ff3f934c37fef89706bdd867431b4fcd to your computer and use it in GitHub Desktop.
[Selenium and python for PDF]

How To Install Selenium Chrome On Centos 7 Last Updated: 2020-05-23

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 wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm 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.

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) If you see following error about chrome version that means your Chromedriver and Chrome versions are out of sync. Go here https://chromedriver.storage.googleapis.com/index.html and find the correct version of ChromeDriver.

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment