How to Build a Create Auto-Login Bot using Python and Selenium

Gmail login

Hello friends today we gonna learn about How to Build a Create Auto-Login Bot using Python and Selenium. So read this article, How to Build a Create Auto-Login Bot using Python and Selenium step by step so you may understand it in a better way. If you have query related to same article you may contact us. So Lets begin:

Guide: How to Build a Create Auto-Login Bot using Python and Selenium

Automation is undoubtedly one of the most coveted skills a programmer can possess. Automation is mostly used for tasks that are repetitive, boring, time consuming, or else inefficient without the use of a script.

With web automation, you can easily create a bot to perform various tasks on the Internet, for example to track competitive hotel rates on the Internet and determine the best price.

Personally, I have always found log in to my email fairly repetitive and boring, so just for the sake of a simple example to get you started with web automation, let’s get a automated Python script to log in with a single click to a Gmail account.

Installation and configuration

In this tutorial we go the following tools

  1. Python programming language
  2. Google Chrome browser
  3. Toolkit for the automation of the browser Selenium
  4. Chrome Driver web driver for Chrome

For our program we will specifically use the Python programming language version 2.7.11It’s critical that we have a fairly new version of Python 2 because it comes with PIP, which allows us to install third-party packages and frameworks that we need to automate our scripts.

Once installed, restart your computer to implement the changes. Use the pip install selenium command to download the Selenium web automation toolkit to Python. With selenium, we can programmatically scroll, copy text, fill out forms and click buttons

Install Selenium

Finally, download it Selenium Chrome Driver Executable, which will open Google Chrome as needed to perform our automated tasks. The Chrome driver is just a way to open Google Chrome (which should already be installed) access standard browser operations programmatically

Simply download the most recent ZIP file from here, extract the chromedriver.exe executable and place the executable in any folder. Make sure to note where your executable is because we need it once we get started

Start the program

As mentioned earlier, we use the Selenium framework for web automation to log in programmaticallyThe first order of business is to import any module we need from the Selenium Python library we installed earlier with PIP.

Let’s open IDLE or some other code editor, create a new Python file with .py extension, and import the following modules

from selenium import web driver from selenium.webdriver.common. by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expects expected_conditions as EC

Next we will make two strings that represent our username and password for the email account. Pay attention to capital letters, especially in your password string.

usernameStr = “putYourUsernameHere” passwordStr = “putYourPasswordHere”

Now that we have everything set up up To start the login process, we have to actually command a browser window to open Google Chrome, and go to the Gmail login page

If you haven’t done this yet, make sure your Python script is saved in the same location as the chromedriver.exe executable we have extracted before.

browser = webdriver.Chrome () browser.get ((‘https://accounts.google.com/ServiceLogin?”service=mail&continue=https://mail.google”.com/mail/#identifier’))

Finding our element

We successfully got the browser to open Gmail, but now we need to find the input fields on the web page, where we can enter our username and password

We can do this easily with the built-in Chrome Developer Tools. All we have to do is right-click on the input fields and select the “Inspect” menu.

Find Element in Developer Tools

Now it’s just a matter of using HTML ID attributes to find the elements programmatically.

In the code below we are simple search for the username input field by id, and filling with the desired text. Than we are search for the next button which goes over with a quick animation before asking us for the password.

The send_keys () and click () commands do exactly what their names suggest – send_keys () simulates keystrokes in the desired element and click () simulates a mouse click

# enter the username and press the next button username = browser.find_element_by_id (‘Email’) username.send_keys (usernameStr) nextButton = browser.find_element_by_id (‘next’) nextButton.click ()

We can do the same for the password input field as well as for login buttonHowever, these two items appear on the page only after an animated transition

That said, we need the program wait a few seconds before continuing to search for elements. For the most part, this code phase is no different from the previous one. We just need to instruct the browser wait a maximum of 10 seconds before you find the password.

# wait for transition and continue with itemspassword = WebDriverWait (browser, 10) .until (EC.presence_of_element_located ((By.ID, ‘Passwd’))) password.send_keys (passwordStr)

signInButton = browser.find_element_by_id (‘signIn’) signInButton.click ()

Final Words

You just finished make a bone who visits a web page, enters your username and password and logs you in successfully, automation of the whole process with a single click. I know this was a simple demonstration, but the possibilities are endless.

On the same note, be careful how you use this skill. Some people use bots and automated scripts to enter sweepstakes thousands of times, completely ignoring the terms and conditions. Others use them for more malicious intent.

Just be sure to use automation purposefully and carefully because it really is one much needed skill in the programming community!

Editor’s Note: This is a post written for Hongkiat.com by Malik BrahimiMalik is a developer in the Greater Boston area who loves food, football and programming (favorite language Python).

back to menu ↑

How to Build a Create Auto-Login Bot using Python and Selenium: benefits

  • The How to Build a Create Auto-Login Bot using Python and Selenium tutorial is free .
  • This guide already helps so many users follow up with interest in a timely manner.
  • The price of the How to Build a Create Auto-Login Bot using Python and Selenium guide is free.

back to menu ↑

Faq

Tutorial summary of How to Build a Create Auto-Login Bot using Python and Selenium

In this guide, we told you about the How to Build a Create Auto-Login Bot using Python and Selenium; please read all steps so that you understand How to Build a Create Auto-Login Bot using Python and Selenium in case if you need any assistance from us, then contact us.

How this tutorial helping you?

So in this guide, we discuss the How to Build a Create Auto-Login Bot using Python and Selenium, which undoubtedly helps you.

What is actual time in which this method complete?

The time to complete the How to Build a Create Auto-Login Bot using Python and Selenium tutorial is 10+ minutes.

What are the supported Device?

PC Laptop or Desktop


back to menu ↑

Final note

I hope you like the guide How to Build a Create Auto-Login Bot using Python and Selenium. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

For our visitors: If you have any queries regards the How to Build a Create Auto-Login Bot using Python and Selenium, then please ask us through the comment section below or directly contact us.
Education: This guide or tutorial is just for educational purposes.
Misinformation: If you want to correct any misinformation about the guide “How to Build a Create Auto-Login Bot using Python and Selenium”, then kindly contact us.
Want to add an alternate method: If anyone wants to add more methods to the guide How to Build a Create Auto-Login Bot using Python and Selenium, then kindly contact us.
Our Contact: Kindly use our contact page regards any help. You may also use our social and accounts by following us on Whatsapp, Facebook, and Twitter for your questions. We always love to help you. We answer your questions within 24-48 hours (Weekend off).
Channel: If you want the latest software updates and discussion about any software in your pocket, then here is our Telegram channel.

Compsmag
Logo