我已经尝试了以下方法,但效果很好。您只需添加足够的等待时间
WebDriver driver = new FirefoxDriver(); WebDriverWait wait = new WebDriverWait(driver, 60 ); driver.get("https://www.gmail.com"); driver.findElement(By.id("Email")).sendKeys("xxx"); driver.findElement(By.id("next")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd"))).sendKeys("xxx"); driver.findElement(By.id("signIn")).click(); String cbox = "//table[@]//div[@]"; String delete = "//div[@]/div[@]"; wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(cbox))); int count = 1; List<WebElement> lst = driver.findElements(By.xpath(cbox)); System.out.println("Total number of checkboxes are t: " + lst.size()); for (int i = 0; i < lst.size(); i++) { WebElement wwe = lst.get(i); wwe.click(); System.out.println("Checked on checkbox number t: " + count); count++; } wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(delete))).click(); try { WebElement deleteButton = driver.findElement(By.xpath(delete)); boolean flag = deleteButton.isEnabled(); if (flag) { System.out.println("nDelete button is enabled"); } else { System.out.println("nDelete button is not enabled"); } deleteButton.click(); } catch (Throwable t) { System.out.println("nUnable to locate delete button"); System.out.println("The exception occuring is t: " + t); }


