Step by Step Guide to Install Selenium in Google Colab

In this tutorial i wll walk you through the process step-by-step so that you can have Selenium up and running on your Google Colab notebook in no time.

Step by Step Guide to Install Selenium in Google Colab

Installing Selenium on Google Colab can be a bit tricky, especially if you’re new to using Selenium or Google Colab. In this tutorial, we’ll walk you through the process step-by-step so that you can have Selenium up and running on your Google Colab notebook in no time.


Install Selenium

First, you’ll need to open your Google Colab notebook. Once you’re in, you’ll want to install Selenium by running !pip install selenium in the command prompt. This will install the Selenium library on your Colab notebook.

!pip install selenium

Install Chromium browser and driver

!apt-get update
!apt-get install chromium chromium-driver

Create Selenium options

This is an import part because the selenium will not work like usual in your google colab environment, because google colab is Ubuntu terminal based without gui so selenium webdriver will crash immediately upon start so you can add below-mentioned options.

def web_driver():
    options = webdriver.ChromeOptions()
    options.add_argument("--verbose")
    options.add_argument('--no-sandbox')
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    options.add_argument("--window-size=1920, 1200")
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(options=options)
    return driver
    
  

Now we can call this function to initiate our chrome webdriver

driver = web_driver()

driver.get('https://www.google.com')

driver.quit()

Conclusion

Finally, the selenium is deployed and ready to be used for automaton and web scraping tasks. Remember that since the environment of Google colab is linux based without gui, so it's not going to launch browser without headless mode.