Monday 19 December 2011

Simple Gmail login automation with Selenium WebDriver



Simple Steps:


1. Go to  http://mail.google.com
2. Enter your user name 'yourgmailid'
3. Enter your password 'yourpassword'
4. Login
5. Goto Sent mail
6. Logout




Simple Code:



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




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("yourgmailid")


passw=driver.find_element_by_id("Passwd")
passw.send_keys("yourpassword")


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()

Simple explanation:

Select your browser
driver= webdriver.Chrome("E:\QA\Resource\WEBDRIVER\chromedriverserver\chromedriver.exe")
can also use
driver= webdriver.Firefox() or
driver= webdriver.Ie()


Choose your destination:
driver.get("http://mail.google.com")


Find element:
emailid=driver.find_element_by_id("Email")


how?
<input id="Email" type="text" value="" name="Email" spellcheck="false">


or?


<input id="Email" type="text" value="" name="Email" spellcheck="false">
emailid=driver.find_element_by_name("Email")


more? YES

find_element_by_xpath
find_element_by_css_selector
find_element_by_class_name
find_element_by_link_text
etc


Enter text:
remember from selenium.webdriver.common.keys import Keys?
emailid.send_keys("yourgmailid")


Handle iframe:
driver.switch_to_frame('canvas_frame') 
How?


For first part visit Hello World! WebDriver with Python on Win 7





40 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Wrong comment earlier. Very good initiative :)

    ReplyDelete
  3. I used these lines in ruby:

    @selenium = Selenium::SeleniumDriver.new 'localhost' , 4444, '*firefox' , 'http://www.gmail.com' , 10000

    @selenium.type "Email", "yourid"
    @selenium.type "Passwd", "yourpassword"
    @selenium.click "//input[@value='Sign in']"
    @selenium.wait_for_page_to_load "30000"
    sleep 5
    @selenium.click "link=Sent Mail"
    @selenium.click "link=yourprofilename"
    @selenium.click "link=Sign out"
    @selenium.wait_for_page_to_load "30000"

    ReplyDelete
  4. আল আরমান I guess you are using Selenium RC, right?

    For Webdriver ruby bindings

    require 'selenium-webdriver'
    driver = Selenium::WebDriver.for :firefox

    ReplyDelete
  5. by the way after 'sleep 5'
    you need to select iframe 'canvas_frame', when exporting code from IDE this part always skipped. :)

    ReplyDelete
  6. Merci
    aswqergh
    Probably one of the most talked about stores in Paris,Isabel Marant Sneakers

    ReplyDelete
  7. wesofttech.com Call 1-888-505-6485 (Toll Free) for Gmail Technical Support.Gmail Password Recovery, Gmail Tech Support, Gmail support number and Gmail Help etc.

    Visit Link- Gmail Support

    ReplyDelete
  8. hi thanks to this writer for this nice blog and this good information
    other useful link - Gmail Tech Support

    ReplyDelete
  9. I have a smart solution for this using Selenium IDE. I could go to composer text area by just using its class (class=editable LW-avf). For detailed article, please refer to http://www.seleniumhq.in/2013/04/automatically-login-to-gmail-and-send.html

    ReplyDelete
  10. wesofttech.com Call 1-888-505-6485 (Toll Free) for Gmail Technical Support.Gmail Password Recovery, Gmail Tech Support, Gmail support number and Gmail Help etc.

    To get Gmail Technical Support ,Please visit the link.

    Thankyou
    Lacy Brown


    ReplyDelete
  11. mm nice post but... when i tried to switch to"canvas_frame" its throwing an error "Unable to locate frame: canvas_frame" you got any other solution for this....

    ReplyDelete
  12. This is a really good read for me.I like the way you describe all the things and the examples.Thanks.
    Visit:- Gmail Help

    ReplyDelete
  13. hai, i am getting the login pageand my email id is been entered, and the code is getting strucked at password, and not moving further,and even i checked with Next.Click() also, can u help me over this.

    the code i added a bit is as below

    emailid=driver.find_element_by_id("Email")
    emailid.send_keys("sujithkumar446@gmail.com")

    Next = driver.find_element_by_id("Next")
    Next.click()


    passw=driver.find_element_by_id("Passwd")
    passw.send_keys("XXXXXXXXXXX")


    and getting a traceback error at password and now after adding the Next i am stucking at Next itself

    ReplyDelete
    Replies
    1. text_area = driver.find_element_by_name('Email')
      text_area.send_keys("email...")
      time.sleep(1)
      google_button = driver.find_element_by_id('next')
      google_button.click()
      time.sleep(1)
      text_area = driver.find_element_by_name('Passwd')
      text_area.send_keys("pass...")
      time.sleep(1)
      google_button = driver.find_element_by_id('signIn')
      google_button.click()

      Delete
  14. I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.

    Digital Marketing Training in Chennai

    ReplyDelete
  15. Yes. thank you so much. and now i show you how to login hotmail account http://howtoget.wiki/hotmail-login-hotmail-sign-up/

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. https://stitchclothes.com here we stitch clothes as per your design and selction

    ReplyDelete
  18. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
    msn.com hotmail sign in

    ReplyDelete


  19. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....

    Shriram Magizhchi
    Shriram Magizhchi Guduvancheri
    Shriram Magizhchi price
    Shriram Magizhchi Guduvancheri Chennai
    Shriram Magizhchi apartments
    Shriram Magizhchi flats
    Shriram Magizhchi review

    ReplyDelete
  20. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),

    ReplyDelete
  21. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    python training in chennai
    python course in chennai
    python training in bangalore

    ReplyDelete
  22. To automate gmail application and send email using attachment below article can help.
    In this article below operations are completed:
    1) Launch chrome browser
    2) Open Gmail URL
    3) Enter Email ID and Password
    4) Navigate to INBOX
    5) Click on Compose email and enter details with attachment
    6) Send email.
    Link to article: http://mundrisoft.com/tech-bytes/automate-gmail-login-process-using-selenium/

    ReplyDelete
  23. A fantastic blog with a lot of useful information. I would like to get updates from you. Keep blogging. All the best.
    It really helps me to counteracts the technical issues that I have been facing with my Gmail Error code issues for a while. Do you Recover Gmail Error code recently and unable to recover your account? Call us at Gmail live chat and get every possible detail in that regard. Your issues will be handled by certified professionals.

    ReplyDelete
  24. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging...
    aws training in chennai | aws training in annanagar | aws training in omr | aws training in porur | aws training in tambaram | aws training in velachery

    ReplyDelete
  25. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging...

    AWS training in Chennai

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training


    ReplyDelete
  26. Excellent and very cool idea and great content of different kinds of the valuable information's.

    Apache Spark Training in Pune
    Python Classes in Pune

    ReplyDelete
  27. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog.

    Aws Training in Chennai

    Aws Training in Velachery

    Aws Training in Tambaram

    Aws Training in Porur

    Aws Training in Omr

    Aws Training in Annanagar

    ReplyDelete