简体   繁体   中英

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

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.

在此处输入图像描述

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

Javascript code which through you can delete open email from Gmail.

let down = new MouseEvent('mousedown');
let up = new MouseEvent('mouseup');
let elem = document.getElementsByClassName('nX')[0];
elem.dispatchEvent(down);
elem.dispatchEvent(up);

Thanks.

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']

组元素

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM