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

0 votes
May 20 in Selenium by Pratyush
262 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 by Abha
• 16,440 points

Related Questions In Selenium

0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
5,777 views
+9 votes
13 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,280 points
47,753 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 in Selenium by Surya
• 950 points
56 views
0 votes
1 answer

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,050 points
260 views
0 votes
1 answer
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,130 points
629 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
257 views
0 votes
1 answer