First unread mail logic | Selenium Forum
M
Posted on 12/01/2016
Program to automate first unread mail in Gmail:


Logic used :

will open gmail , capture Inbox(text) . if text>=1 , then will open 1st unread mail through xpath


Code:

driver.get("http://gmail.com/");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("xxx@gmail.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys("xxxxx");
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(Keys.ENTER);
Thread.sleep(3000);
String abc=driver.findElement(By.xpath("//span[@class='nU n1']/a[@class='J-Ke n0']")).getText();
System.out.println(abc);
char a=abc.charAt(7);
System.out.println(a);
if(a>=1)
{
driver.findElement(By.xpath("//span[@class='nU n1']/a[@class='J-Ke n0']")).click();
driver.findElement(By.xpath("//table[@class='F cf zt']/tbody/tr[1]/td[5]/div[2]/span")).click();
///driver.findElement(By.xpath("//*[@id=':1k9']/span]")).click();

}
else
{
System.out.println("No First unread mail");
}


Please confirm whether this si correct logic or not.. is there any other logic

M
Replied on 13/01/2016

[quote:3rr95ulc]By.xpath("//span[@class='nU n1']/a[@class='J-Ke n0']"
driver.findElement(By.xpath("//span[@class='nU n1']/a[@class='J-Ke n0']")).click();
driver.findElement(By.xpath("//table[@class='F cf zt']/tbody/tr[1]/td[5]/div[2]/span")).click();
///driver.findElement(By.xpath("//*[@id=':1k9']/span]")).click();
[/quote:3rr95ulc]

these xpaths are very unstable they will keep on changing and overall gmail is one of the hardest website to automate.


start by how handle dynamic xpaths. its explained in the video.


M
Replied on 13/01/2016

that's fine.

But please let me know whether this logic is correct or not.

is there any other logic? to capture 1st unread mail.

It was exercise question in module 17


M
Replied on 13/01/2016

[quote:68nsb8jb]But please let me know whether this logic is correct or not.
[/quote:68nsb8jb]

logic is incorrect as xpaths are wrong.

watch module 17 for how to handle dynamic xpaths