Automate your browser with 5 simple steps with Python and Selenium

Muzamil Nawaz
3 min readJul 3, 2021

--

Photo by Richy Great on Unsplash

Normally non-technical people in corporations are forced to do the jobs consisting of boring and repeating processes. However with the era of computer programming, Automating such tasks has been a fancy as well as useful thing (not all the time, Lol). While taking that into context, we know that web browser is very common thing used by almost every computer user So today we will see how we can automate the processes in our browser within few simple steps.

Technologies and Tools we will use in this exercise:

1- Python

For installation instructions, click here.

2- Selenium and Web driver

For installation instruction, click here.

Photo by Jaimie Harmsen on Unsplash

Now we will write a python program to see how we can automate the login process of Yahoo.

Step 1:

Firstly, import the web driver which is nothing but driver provided by selenium to help us navigate the browser automatically.

Do this in your python program

Step 2:

Set the options for selenium to use through which we will specify what browser we will use, in our case it’s Google chrome.

Make sure to replace the ‘os.path.join ( )’ part with the path of chrome driver which you downloaded while installing and setting up selenium.

Step 3:

Open the initial page you want to begin automation from, in our case it’s Yahoo’s Log in page.

This will open the login page initially when script runs

Step 4:

Go to login page -> Right click on username input field -> Click inspect -> Right click on highlighted part on right side of the browser -> Copy -> Copy full Xpath.

Inspection of element would look like this

then use it in your python code like this:

Now as we have put the username data in respective field successfully. Let’s move to password field by clicking Next button.

Copy the Xpath of Next button in the same way you did for username input field and use it in your code as following:

Note: Repeat the above step for the Password input field and another next button.

Step 5:

Now, you know how to put in text in input fields and click on button in the web page through the automated script. Just execute the script and you will see the browser opening up and loading the Yahoo login page directly with the message that it’s been controlled by some automated driver.

I hope this would be helpful for you, if you have any confusions regarding any step. Please go ahead to ask out in comments, I will try to answer your query.

Till next time, Cheers !!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Muzamil Nawaz
Muzamil Nawaz

Written by Muzamil Nawaz

A software engineer with passion of building systems and ability of fast adaptability. Starting my writing journey, while looking forward to long way :)

No responses yet

Write a response