Bharat Mane Bharat Mane - 17 days ago 19
Java Question

How to click on a Particular email from gmail inbox in Selenium?

I hv to click on a particular email, in that case what should I do? I seen there is a Webtable with multiple indexes, I hv to select 1 & click on it. does anyone have code how to handle webTables in WebDriver? See exact situation in below screen-
http://screencast.com/t/XRbXQVygNkN6

I was trying with below code -Plz suggest me for rest of the action.

After gmail Login-


1st Ihv clicked on inbox link--->>then Promotions--->>then I hv to click on particular email


WebElement PromotionsSection =driver.findElement(By.xpath("//div[contains(@id,':2y')]"));
PromotionsSection.click();

WebElement email=driver.findElement(By.xpath(".//*[@id=':1g4']/b"));
email.click();

Answer

think that u r in page after login. Now use the below code:

List<WebElement> email = driver.findElements(By.cssSelector("div.xT>div.y6>span>b"));

for(WebElement emailsub : email){
    if(emailsub.getText().equals("Your Subject Here") == true){

           emailsub.click();
           break;
        }
    }

this will just click on ur mail if it matches the subject string.