Introduction

Imagine testing a web page by simulating a user interacting with the web page. A simple task, right? Well, maybe!

Read on to learn about how we can automate simple tasks to help speed up the testing process. We will review what Selenium is, what it can do, and how to implement it.

To demonstrate what Selenium can do, we have created tutorial on how to automate a user login to a web page using Python.  We will show you how to install Python3, Selenium, and all the required dependencies; instantiate a browser in order to request https://facebook.com/; and create a script to log a user in using their email address and password.

What is Selenium?

Selenium can be used to automate and control browser activities. Its main purpose is to automate web application testing, but it has many other capabilities. In our example below, we will learn how to use Selenium to automate simple tasks, therefore saving us time from having to perform a task repeatedly.

Getting started

A few things before we continue. We will be using Python3 to write a script that implements a Selenium module to automate a browser task. To get started, we will need a webdriver. For this example, we will be using geckodriver, a Firefox webdriver.

INSTALLING DEPENDENCIES

Let’s install the following:

1. Python3: Here, we are using Archlinux (which is installed by default). You can go here to learn how to install Python3 on Windows.  Once you have downloaded the Python installer, follow the next steps:

If you are using Windows, you can can use pip to install the Selenium module:

Or, you can download geckodriver from Mozilla repository. Be sure to download the appropriate version for your OS. In this example, I will be downloading the Windows gecko driver and adding it to Windows PATH:

Now that we have our required dependencies installed, let’s start coding:

 

Importing required modules

  • Selenium: to automate our browser task.
  • Time: this will help us pause our script and give the page time to fully load.

Once Facebook.com is done loading, we will need to use the following elements:

  1. Email input box
  2. Password input box
  3. Log in button

Congratulations! You have just completed your first Selenium automated script. The module is not limited to only testing. You can also automate regular tasks and in doing so, save time!