我正在做硒实践,并希望从我的Gmail收件箱中删除约30K条未读邮件。我困于选择未读复选框。尝试了很多Locators和xpath,但是我的xpath选择了所有邮件的复选框。SeleniumJava:删除Gmail中的未读邮件
任何人都可以建议如何选择封未读邮件的复选框
PFB的Java代码硒
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Unread_Gmail {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier");
driver.findElement(By.id("Email")).sendKeys("*********@gmail.com");
driver.findElement(By.id("next")).click();
driver.findElement(By.id("Passwd")).sendKeys("******");
driver.findElement(By.id("signIn")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[@class='G-tF']/div[1]/div")).click();
driver.findElement(By.xpath(".//*[@id=':z2']/div")).click();
//driver.findElement(By.xpath("//div[@class='J-J5-Ji J-JN-M-I-Jm'][1]")).click();
//driver.findElement(By.xpath("//div[@class='J-J5-Ji J-JN-M-I-Jm']")).click();
//driver.findElement(By.id("z2")).click();
//driver.findElement(By.xpath("//div[@class='J-N-Jz']")).click();
//driver.findElement(By.id("z2")).click();
}
}
我检查过HTML DOM和ID是动态的.... –
试着寻找@selector =“未读”然后,它应该稳定 – Gyrotank