Automate Login With Python And Selenium (2024)

How to login to websites automatically

Automate Login With Python And Selenium (1)

Automate Login With Python And Selenium (2)

Published in

·

5 min read

·

Jul 18, 2022

--

Automate Login With Python And Selenium (3)

Automating the login process can be helpful in accessing the information on websites. For example, you may want to update your account settings automatically, or you may want to scrape some web pages and extract some data, but you are first required to log in with your credentials.

In this article, I will present a Python program that will access the GitHub website, enter login credentials, and sign into the website.

Disclaimer: This article is only for educational purposes. We do not encourage anyone to scrape websites, especially those web properties that may have terms and conditions against such actions.

Review the Web Page’s HTML Structure

First, we need to understand the structure and contents of the HTML tags within the web page. For this project, we will be using the GitHub login webpage (shown below). You can access this webpage by selecting this link.

Automate Login With Python And Selenium (4)

We can sign into this website by finding the input fields, entering the required data, and clicking the Sign in button. To find the HTML tags for the input fields on this web page, right, click anywhere on the web page, select inspect from the drop-down list, click the arrow icon in the upper left-hand side of the screen with the HTML and then click the Username or email address input field. This will result in the following screen being displayed.

Automate Login With Python And Selenium (5)

We can see that the Username or email address field has an id = “login_field” and the password field has an id = “password”. If you scroll down a little you will see that the Sign in button has a name = “commit”.

So if you want to enter a username, you would follow these steps.

1. Create a variable containing your username or email address.

2. Find the username field where id = “login_field”.

Automate Login With Python And Selenium (2024)
Top Articles
Latest Posts
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 5834

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.