How to access emails in gmail and opening the latest one from unread mails using Selenium Webdriver?

+1 vote
May 20, 2019 in Selenium by Pratyush
5,434 views

1 answer to this question.

0 votes

Hey Pratyush, to access emails from your gmail inbox and opening the latest Unread email using Selenium Webdriver, you can use this code snippet:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Abha_Rathour\\Downloads\\ExtractedFiles\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

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

driver.get("https://gmail.com/");

driver.findElement(By.id("identifierId")).sendKeys("Email_Id");

driver.findElement(By.className("CwaK9")).click();

driver.findElement(By.xpath("//*[@id=\"password\"]/div[1]/div/div[1]/input")).sendKeys("Password");

driver.findElement(By.className("CwaK9")).click();

// System.out.println("Title of Page: " + driver.getCurrentUrl());

List<WebElement> unreademail = driver.findElements(By.className("zE"));



System.out.println("Total No. of Unread Mails: " + unreademail.size());

// real logic starts here

for(int i=0;i<unreademail.size();i++){

System.out.println(unreademail.get(i).getText());

}

unreademail.get(0).click();

Thread.sleep(3000);

driver.close();
answered May 21, 2019 by Abha
• 27,930 points

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
13,531 views
+10 votes
15 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
121,683 views
0 votes
1 answer
0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 13, 2019 in Selenium by Surya
• 970 points
1,824 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,770 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,752 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,733 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,096 views
0 votes
1 answer