Bharat Mane Bharat Mane - 1 year ago 121
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-

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')]"));;

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

Answer Source

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){


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download