Unable to select the all unread mail in Gmail through selenium

301 views
Skip to first unread message

Avinash Mavi

unread,
May 31, 2017, 10:32:31 AM5/31/17
to Selenium Users
I am using the filter dropdown to select the Unread mails.

Selenium Code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class testing {
public static void main(String[] args) throws InterruptedException {
     WebDriver driver = new FirefoxDriver();
        String baseUrl = "https://www.gmail.com";
                
        driver.get(baseUrl);
       
        driver.findElement(By.id("identifierId")).sendKeys("**********@gmail.com");
        
        driver.findElement(By.id("identifierNext")).click();
        
        Thread.sleep(3000);
        
        driver.findElement(By.xpath(".//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("*****");
        
        driver.findElement(By.id("passwordNext")).click();
        
        Thread.sleep(4000);

        driver.findElement(By.xpath("//*[@id=':2t']/div[2]")).click();

        Thread.sleep(3000);
       
        // to click the unread mail in the dropdown

        WebElement value=driver.findElement(By.xpath("//div[7]/div/div[4]/div"));
        Actions act=new Actions(driver);
        act.moveToElement(value).build().perform();
        value.click();

        Thread.sleep(2000);         
             
        //driver.close();
        //System.exit(0);
      
}

}

Doug Dragon

unread,
May 31, 2017, 1:27:54 PM5/31/17
to Selenium Users
Why are you automating Gmail? Unless you work on the Gmail team, I would think you'd much rather want to use Gmail's API.

Monika Singhal

unread,
Jun 2, 2017, 2:08:17 AM6/2/17
to Selenium Users
Hi,

I see the xpath which you have used for selecting unread option is incorrect. You have to modify that xpath. 

Modification which can be made in the xpath:

       WebElement value=driver.findElement(By.xpath("//div[@selector='unread']/div"));

Thanks & Regards,
Monika
Reply all
Reply to author
Forward
0 new messages