我试过的代码:
driver.findElement(By.xpath("//div[@aria-label='Delete' and @role = 'button']"));
和
driver.findElement(By.xpath("///div[@class='iH bzn']//div[@aria-label='Delete' and @role = 'button']"));
运行代码时,selenium 不接受此路径。 我也尝试过鼠标悬停,但它对我不起作用。 任何人都可以帮助我吗? 请找到附件图片
提前致谢。
如果有人可以用 java 脚本帮助删除电子邮件,那也会有帮助
最佳答案
首先你需要鼠标悬停
到groupElement
:
//div[@class='iH bzn']//div[@class='G-tF']//div[2][@class='G-Ni G-aE J-J5-Ji']
删除图标需要从另一个元素触发才能可见:
//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();
导入后:
import org.openqa.selenium.interactions.Actions;
关于javascript - Selenium 网络驱动程序 : How to delete an open email from Gmail using selenium webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58727375/