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();