Selenium Webdriver : How to delete an open email from Gmail using selenium webdriver

kunal soni :

Code that i have tried :

 driver.findElement(By.xpath("//div[@aria-label='Delete' and @role = 'button']"));

and

 driver.findElement(By.xpath("///div[@class='iH bzn']//div[@aria-label='Delete' and @role = 'button']"));

This path is not accepted by selenium while running the code. I have tried Mouse hover as well but its not working for me. Anybody can help me with this? Please find the attached image

Thanks in advance.

enter image description here

If someone can help with java script to delete email , it would be also helpful

frianH :

First you need Mouse hover to groupElement:

//div[@class='iH bzn']//div[@class='G-tF']//div[2][@class='G-Ni G-aE J-J5-Ji']

groupElement

The delete icon need trigger from another element to visible:

//add some wait here
WebElement groupElement = driver.findElement(By.xpath("//div[@class='iH bzn']//div[@class='G-tF']//div[2][@class='G-Ni G-aE J-J5-Ji']"));
Actions action = new Actions(driver);
action.moveToElement(groupElement).build().perform();
driver.findElement(By.xpath("//div[@aria-label='Delete']//div[@class='asa']")).click();

Following import:

import org.openqa.selenium.interactions.Actions;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=322754&siteId=1