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
13,660 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
• 28,140 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 6, 2020 in Selenium by Sri
• 3,190 points
19,531 views
+11 votes
17 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
204,681 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 14, 2019 in Selenium by Surya
• 970 points
5,027 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,500 points
14,601 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,697 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,910 points
7,847 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 3, 2020 in Selenium by Sri
• 3,190 points
8,322 views
0 votes
1 answer
0 votes
1 answer

How to read test data from an excel sheet and use it to test facebook login in Selenium Webdriver?

Hi Mohan, you can use following code ...READ MORE

answered Jul 17, 2019 in Selenium by Abha
• 28,140 points
14,097 views