![](/img/trans.png)
[英]Could not run exe file through java code, in Selenium WebDriver
[英]Run Java code in loop in Selenium Webdriver
我有兩個帶有文本“ 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
例如(截屏)
//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();
}
}
任何建議我該如何編寫代碼來做到這一點? 在此處查看“圖像”以了解我正在嘗試做的示例圖像
修改這段代碼,如下所示:
// 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();
}
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.