0

I have two button with text "x" and they both have same cssSelector a.aui-button.aui-button-link.aui-restfultable-delete.aui-restfultable-delete-small

The code below is able to click on the first "x", however fails because there is a pop up window asking for confirm to delete.

I want the code to click on first "x" and than click on "Delete" to confirm on the pop up window and repeat for the second "x". The cssSelector for "Delete" in Pop up window is aui-button.js-confirm-action-button

E.g. (Screenshot)

//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();
        }
    }

Any Suggestion how can I write code to do this? Check Image here to get an idea of what I am trying to do Example Image

6
  • What error messages are you receiving and where is the failure happening in your example block of code? Commented Jul 21, 2016 at 10:12
  • have u tried by switching this alert or is this have any frame or not? Commented Jul 21, 2016 at 10:23
  • @Tom Trumper, failure occurs when the pop up for confirmation comes up as in the example screenshot. I want the code to click on "Delete" and move on the do the same for the next "x". Commented Jul 21, 2016 at 10:44
  • So what happens when you try to click the delete button that appears after clicking the 'x'? Your example code only appears to click the 'x's. Commented Jul 21, 2016 at 11:05
  • @user3682764 what do you mean by failure occurs?? If there is any exception need to share it..and your pop-up is JavaScript alert or html popup window?? Commented Jul 21, 2016 at 17:53

1 Answer 1

1

Modify the piece of code as shown below:

// 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();  
    }
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. If it answers your question can you please mark this as answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.