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
You probably chose not so automation friendly web app like Gmail to start with. I believe they have deliberately developed Gmail client side in such a way that its harder for a Robot to perform actions.
As for your question, I think the delete button appears a little after check boxes are clicked. So I believe you will have to explicitly wait for the button to appear. It's also possible that your xpath is not correct.
You could try this,
WebDriverWait wait = new WebDriverWait(driver, 60 /*timeOut in Seconds*/);
wait.until(ExpectedConditions.
visibilityOfElementLocated(By.css("div[data-tooltip='Delete']"))).click();
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<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);
}