Thursday 13 October 2016

Automation for login and logout of GMAIL using Python.

Basic setup required:

First we need to do basic setup of python and the "selenium" module installation.

For basic python setup see the following video's:
Installation of selenium module using pip:

For installing a python module see the following video : https://www.youtube.com/watch?v=5zEQaYBukz4

pip install selenium


Following code is used to login and logout from a GMAIL account:

# Modules to be imported.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Your login details.
email = "<email>@gmail.com"
passwd = "<your password>"

# Browser : Firefox.
driver = webdriver.Firefox()
driver.get("http://www.gmail.com")
time.sleep(2)

# GMAIL login.
username=driver.find_element_by_css_selector("#Email")
username.send_keys(email)
time.sleep(2)
next=driver.find_element_by_css_selector("#next")
next.click()
time.sleep(2)
password=driver.find_element_by_css_selector("#Passwd")
password.send_keys(passwd)
time.sleep(2)
login=driver.find_element_by_css_selector("#signIn")
login.click()

# GMAIL logout.
logout1=driver.find_element_by_css_selector(".gb_8a")
logout1.click()
time.sleep(2)
logout2=driver.find_element_by_css_selector("#gb_71")
logout2.click()

# Closing Browser.
driver.quit()

Note:

Keep seeing my blog for different automation thing that we do manually in our daily life.

2 comments:

  1. To go with the sleek Gmail Redesign login Send GMail Emails and reduce the number of folders on your left side panel, we removed our Tracked folder. You can still find all tracked emails inside your Sent folder.

    ReplyDelete
  2. It’s really Nice and Meaningful. It’s really cool Blog. You have really helped lots of people who visit Blog and provide them Useful Information. Thanks for Sharing.DataScience with Python Training in Bangalore

    ReplyDelete