Notes for Selenium with Python3.
Created on: 2018-10-28
we can install selenium with pip:
sudo pip3 install selenium
To run Firefox browser we need to install geckodriver. Let's head over to geckodriver releases page and get the latest version of geckodriver for Linux 64 bit. Downloaded file will look like this geckodriver-vx.y.z-linux64.tar.gz. Now we will extract the .tar file:
tar -xvzf geckodriver*
Make it executable:
chmod +x geckodriver
Move to /usr/local/bin/:
sudo mv geckodriver /usr/local/bin/
Remove the .tar file:
rm geckodriver*
To run Chrome and Chromium we need to install chromedriver which we can get from chromedriver download page. Get the latest version of chromedriver for Linux 64 bit. Downloaded file will look like this chromedriver_linux64.zip. Now we need to unzip the .zip file:
unzip chromedriver*
Note
if you don't have unzip install with sudo apt install unzip
Make it executable:
chmod +x chromedriver
Move to /usr/local/bin/:
sudo mv chromedriver /usr/local/bin/
Remove the .zip file:
rm chromedriver*
To get started we need to import webdriver from selenium:
from selenium import webdriver
We can choose Firefox, Chrome or Chromium as our client browser:
browser = webdriver.$client_browser()
Where $client_browser= 'Firefox', 'Chrome' or 'Chromium'.
After the selecting the browser we can use the get() method to open a URL.:
browser.get('url.tld')
For exapmle:
browser.get('https://duckduckgo.com')