Sunday, May 11, 2014

How to login, get the number of mails in inbox and logout from the gmail account.


import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class InboxCount {

    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        System.out.println("enter ur gmail id: ");
        String id = kb.nextLine();
        System.out.println("enter ur gmail pass: ");
        String password = kb.nextLine();
       
       
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&hl=en&emr=1&elo=1");
        driver.findElement(By.id("Email")).sendKeys(id);
        driver.findElement(By.xpath("//input[@id='Passwd']")).sendKeys(password);
        driver.findElement(By.xpath("//input[@type='checkbox']")).click();
        driver.findElement(By.name("signIn")).click();
       
        String inbox = driver.findElement(By.xpath("//a[@href='https://mail.google.com/mail/u/0/#inbox']")).getText();
        System.out.println(inbox);
       
        //sign out
        driver.findElement(By.xpath("//span[@class='gb_V gbii']")).click();
        driver.findElement(By.linkText("Sign out")).click();
       
        driver.close();
       
    }
}

6 comments:

  1. Hi,

    Please give the code to count the number of unread emails present inside the inbox

    ReplyDelete
  2. Please find the code here for get the unread mail.

    http://selenium-makeiteasy.blogspot.in/2014/05/how-to-login-get-number-of-mails-in.html

    ReplyDelete
  3. Hi Sanjay Kumar Ji,You are doing a Good Job of helping budding Selenium Testers(in Automation) like US.Please continue with your great work and Please provide as many Realtime Examples on concepts as Possible.ALL THE BEST.MAY GOD BLESS YOU.

    ReplyDelete
  4. your Blog is useful for those who want to learn testing

    ReplyDelete
  5. please provide information about testlink management tool how to install

    ReplyDelete
  6. Hi Sanjay! i m stuck to delete the marked mail from gmail.com while searching by any word so could you provide the code for the same...
    thanks

    ReplyDelete