Skip to content

Instantly share code, notes, and snippets.

@qustosh
Forked from kingofhawks/selenium_login_gmail.py
Created January 16, 2014 08:52
Show Gist options
  • Save qustosh/8451767 to your computer and use it in GitHub Desktop.
Save qustosh/8451767 to your computer and use it in GitHub Desktop.
Use selenium to auto login gmail account
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver= webdriver.Firefox()
#driver= webdriver.Chrome("E:\QA\Resource\WEBDRIVER\chromedriverserver\chromedriver.exe")
driver.get("http://mail.google.com")
emailid=driver.find_element_by_id("Email")
emailid.send_keys("username")
passw=driver.find_element_by_id("Passwd")
passw.send_keys("password")
signin=driver.find_element_by_id("signIn")
signin.click()
time.sleep(10)
driver.switch_to_frame('canvas_frame')
sentmail= driver.find_element_by_link_text('Sent Mail')
sentmail.click()
time.sleep(10)
sentmail= driver.find_element_by_link_text('Your Name')
sentmail.click()
lout= driver.find_element_by_link_text('Sign out')
lout.click()
@rohitgupta
Copy link

Hi,
Can you check as why my element of password is not found.

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#url = input('Enter the URL: ')
loginname=input('Enter Email Id:')
gmailpassword=input('Enter Password:')

driver= webdriver.Chrome()
driver.get('http://www.gmail.com/')
print ("Opened Gmail")
sleep(1)

emailid=driver.find_element_by_id("identifierId")
emailid.send_keys(loginname)
print ("Email Id entered")
sleep(1)

driver.find_element_by_xpath('//*[@id="identifierNext"]/content').click()

passw=driver.find_element_by_xpath('//*[@id="password"]/div[2]').click()
#passw=driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/div[1]/div/div[1]/div/div[1]/input').clear()
passw.send_keys(gmailpassword)

signin=driver.find_element_by_name("//*[@id='password']/div[1]/div/div[1]/input")
signin.click()

time.sleep(10)

driver.switch_to_frame('canvas_frame')

sentmail= driver.find_element_by_link_text('Sent Mail')
sentmail.click()

time.sleep(10)

sentmail= driver.find_element_by_link_text('Your Name')
sentmail.click()

lout= driver.find_element_by_link_text('Sign out')
lout.click()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment