This is a practice test case where i have to login to gmail and click on all the checkbox in the dynamic web table and delete the mails. So i made the following code.
Th
I've tried the following and it worked fine.You just have to add enough wait
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 60 /*timeOut in Seconds*/);
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[@class='F cf zt']//div[@class='T-Jo-auh']";
String delete = "//div[@class='asa']/div[@class='ar9 T-I-J3 J-J5-Ji']";
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(cbox)));
int count = 1;
List 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);
}