Getting started with Selenium (Python)

Selenium is a Python package, that is used for automating tasks in browsers, web scraping, testings, and building bots. It basically controls the web browser in an automated manner.

Introduction to Selenium (Python)

Although we'll discuss Selenium in Python, Selenium can be used with any programming language like Java, C#, etc. It is a widely used package nowadays for testing and web scraping purposes.

Selenium can be used with any browser like Chrome, Firefox, Safari, etc. All we need is a web driver for a browser we want to use, which can be downloaded easily. Those drivers make it possible to automate browsers through the selenium program.


Installing Selenium

Make sure python and pip is installed and then lets run the following command in a terminal,

pip install selenium

Now selenium will be installed in our machine.


Writing first selenium program

Now let's open any text editor and create a new file named app.py.


Import Selenium

The very first step is to import selenium into our program.
from selenium import webdriver


Instantiate Selenium

Now we have to instantiate selenium in python.
browser = webdriver.Firefox()

Note that we need a browser driver to instantiate any web browser. In my case, I'm instantiating the Firefox browser.

Post a Comment (0)
Newer Article Older Article