Selenium is a great framework for automating Web Browsers for testing and other purposes , in this blog we’ll learn how to find and install the correct version of Selenium with Vivaldi browser using two methods .
Install Selenium using pip
So the first thing we’ll do is installing Selenium for python via pip, from your terminal run :
pip install --user selenium
pip is the package installer for Python, --user
is used to install the package to your user home directory avoiding the need for root access (no sudo is needed) .
Selenium needs a WebDriver
Think of the WebDriver as a robot user that uses the browser (Just like a human user) it’s the part responsible for talking to the browser and provides the language bindings for us to make it do different tasks on the browser . Now since there are different browsers types (Chrome , Firefox, ..) , there are different WebDrivers: Vivaldi is based on Chrome so we’ll be using the WebDriver for Chrome that is : ChromeDriver . We need to install the correct version of ChromeDriver that matches our Vivaldi’s Chromium version :
Finding Vivaldi’s Chromium version:
Open Vivaldi and go to the about section menu > Help > About
or open a new tab and past vivaldi://about/
, as you can see in the picture below Vivaldi 4.0 comes with Chromium 91
Getting ChromeDriver
Method 1 : direct download
Open this page , and download the correct version , choose linux
It’ll contain a single file , extract it somewhere you can easily access , for e.g I extracted it in my home directory so its path would be : '/home/mossab/chromedriver'
Ready to try it !
I’ll be using Python’s Interactive Shell for demonstration:
from selenium import webdriver
The webdriver will need two information:
- Where is our custom browser (Vivaldi) : from terminal
which vivaldi
will show that Vivaldi’s binary is in'/usr/bin/vivaldi'
- The path to the ChromeDriver:
'/home/mossab/chromedriver'
Let’s store them in variables :
driverPATH = '/home/mossab/chromedriver'
browserBIN = '/usr/bin/vivaldi'
We’ll set the Browser bin using webdriver.ChromeOptions
as follows:
options = webdriver.ChromeOptions()
options.binary_location = browserBIN
Finally we’ll run the browser and control it via the driver object :
driver = webdriver.Chrome(driverPATH, options=options)
# Get a webpage
driver.get("https://en.wikipedia.org/wiki/Linux")
Method 2 : install the ChromeDriver with pip
if for some reason the first method didn’t work, we can get the ChromeDriver using the pip package chromedriver-py
, but first visit this page to find the exact version to install
pip install --user chromedriver-py==91.0.4472.19
Now instead of setting driverPATH
manually , you can do the following :
import chromedriver_py
driverPATH = chromedriver_py.binary_path
.. and complete the same steps as above .
Conclusion :
One last tip : if when trying to open a url you face a selenium.common.exceptions.InvalidArgumentException
make sure you’re using the full url with the http protocol that is: "https://www.google.com"
instead of "www.google.com"
.
Phew ! That concludes the tutorial , hope it was helpful , if you didn’t understand a step or I made a mistake please feel free to reach me on twitter !
Happy automating 🤖 and stay away from CAPTCHAs !