我正在编写创建并删除模板的脚本。如果脚本失败(在删除模板之前),那么我需要一种在下次脚本运行时删除模板的方法。
我创建了一个if if else循环,但不会删除第二个模板。我究竟做错了什么?非常感谢:)
while (driver.findElements(By.xpath("//div[contains(text(),'Automation_TemplateXX')]")).size() !=0){
// Clicks on Edit Template Button
WebElement SearchTPF = this.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'Automation_TemplateXX')]//following-sibling::div")));
SearchTPF.click();
this.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='content-area-wrapper']")));
// Click Delete Button
WebElement deleteTP = this.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Delete Template')]")));
deleteTP.click();
// Alert Pop Up > Confirm Deletion
wait.until(ExpectedConditions.alertIsPresent());
Alert confirmPop = driver.switchTo().alert();
confirmPop.accept();
this.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='tabPage_thread_id_1002523']//ul[contains(@class, 'list-unstyled') and contains(@class, 'thread-messages') and contains(@class, 'to-print')]")));
log.info("Template was Deleted Successfully, Current url " + driver.getCurrentUrl());
}