我有两个带文字的按钮" x"它们都有相同的cssSelector a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small
下面的代码可以点击第一个" x"但是因为有一个弹出窗口要求确认删除而失败。
我希望代码首先点击" x"而不是点击"删除"在弹出窗口中确认并重复第二个" x"。 cssSelector用于"删除"在弹出窗口中aui-button.js-confirm-action-button
E.g。 (截图)
//Delete all existing Request Types
List<WebElement> allele = driver.findElements(By.cssSelector("a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small"));
// Looping through the elements using for-each loop
for(WebElement eachEle : allele) {
// Checking whether the element is enabled or not
if(eachEle.isEnabled()) {
eachEle.click();
}
}
任何建议如何编写代码来执行此操作?点击此处查看图片,了解我要做的事情Example Image
答案 0 :(得分:1)
修改一段代码,如下所示:
// Initializing the webdriver wait
WebDriverWait wait = new WebDriverWait(driver, 10);
//Delete all existing Request Types
List<WebElement> allele = driver.findElements(By.cssSelector("a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small"));
// Looping through the elements using for-each loop
for(WebElement eachEle : allele) {
// Checking whether the element is enabled or not
if(eachEle.isEnabled()) {
eachEle.click();
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
}
}
希望这有帮助。