Sunday, March 4, 2012

Clicking Compose Button in Gmail using Selenium Webdriver

In Case of Selenium Webdriver use the following code to click on compose button in Gmail:

driver.findElement(By.id("Email")).sendKeys("XXXX@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("password");
driver.findElement(By.id("signIn")).click();

//wait for page to load
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

//this is important to click on any element on gmail page
driver.switchTo().frame("canvas_frame");
//Now , click on compose mail
driver.findElement(By.xpath("//div[contains(text(), 'Compose mail')]")).click();

==========================================================
In Case of Selenium RC use the following code to click on compose button in Gmail:

selenium.clickAt("//div[contains(text(), 'Compose mail')]","50,50");



10 comments:

  1. Hi,i was using SeleniumRC,selenium.clickAt("//div[contains(text(), 'Compose mail')]","50,50");if i use dis also i was not able to get the solution,getting Exception.

    ReplyDelete
  2. After clicking Compose, I can type to and subject. But I failed to type msg body. How can I type message body of Gmail?

    ReplyDelete
  3. Hi i have use this selenium.clickAt("//div[contains(text(), 'Compose mail')]","50,50") even after using this command also am not able to invoke compose screen. Is there any sepcific reason please reply asap.

    ReplyDelete
  4. This can be done very easily with Selenium IDE. The code looks like this.

    -----------------------------
    Command, Target, Value
    setTimeout, 3000,
    open, /mail/u/0/?shva=1#inbox?compose=new
    click, class=aoD hl
    type, //table/tbody/tr[1]/td[2]/div/div/textarea, McKiran@tested.com
    .................
    -----------------------------

    For detailed article, please refer to http://www.seleniumhq.in/2013/04/automatically-login-to-gmail-and-send.html

    ReplyDelete
  5. 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
  6. Hi........I have sent an Emil successfully through selenium automation using Gmail Account Below is the script please find it.....

    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


    driver.findElement(By.xpath("//div[@id=':jb']/div[@class='z0']/div")).click(); // Compose


    selenium.type("//div[@class='wO nr l1']//textarea[@name='to']", "vikramnarlai@gmail.com"); // To

    selenium.type("//div[@class='aoD az6']//input[@name='subjectbox']", "Wanted to SAY HI"); // For Subject

    selenium.type("//div[@class='Ar Au']/div[@class='Am Al editable LW-avf']", "Hi Vikram");// For Message body

    selenium.click("//div[@class='J-J5-Ji']/div[@class='T-I J-J5-Ji aoO T-I-atl L3']"); //send

    ReplyDelete
  7. can any one tell me that how to click on "send" button on gmail using selenium webdriver

    ReplyDelete
    Replies
    1. can anyone tell me that how to click on "Send" button using the cssSelector on gmail (selenium webdriver)

      Delete
  8. //click SEND button in Gmail
    driver.findElement(By.xpath("//div[text()='Send']")).click();

    ReplyDelete
  9. can some one tell me how we can compose gmail with label as'social' using selenium?

    ReplyDelete