Automation is undoubtedly one of the most coveted skills a programmer can possess. Automation is typically used for tasks that are repetitive, boring, time-consuming, or otherwise inefficient without the use of a script.
With web automation, you can easily create a bot to perform different tasks on the web, for instance, to monitor competing hotel rates across the Internet and determine the best price.
Personally, I have always found logging into my email fairly repetitive and boring, so for the sake of a simple example to get you guys started with web automation, let’s implement an automated Python script to log in with a single click to a Gmail account.
Selenium web automation framework in order to log in programmatically. The first order of business is to import every module we’ll be needing from the Selenium Python library which we installed earlier with PIP.
Let’s open IDLE or another code editor, create a new Python file with .pyextension, and import the following modules:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Next, we’ll create two strings that represent our username and password for the email account. Pay attention to capitalization, especially in your password string.
usernameStr = ‘putYourUsernameHere’
passwordStr = ‘putYourPasswordHere’
Now that we have everything set up in order to start the login process, we need to actually instruct a browser window to open Google Chrome and navigate to Gmail’s login page.
If you haven’t done so already, make sure your Python script is saved in the same location as the chromedriver.exe executable we extracted earlier.
browser = webdriver.Chrome()
Next open Chrome Developer Tools. You only need to right-click on the input fields, and select the “Inspect” menu. In the code below, we’re simply searching for the username input field by id, and filling it with the desired text. Then we’re searching for the Next button which transitions with a quick animation before prompting us for the password.
# fill in username and hit the next button
username = browser.find_element_by_id(‘Email’)
nextButton = browser.find_element_by_id(‘next’)
We can do the same thing for the password input field, as well as for the Sign In button. On the other hand, If you need traffic bot on your website just contact Babylon Traffic, they are simply the best in the business.