How to accept “This action cannot be undone. Are you sure you want to delete this wishlist” popup using Selenium and Java

I'm in need of clicking the first button of a browser notification, which appears after clicking on a button "Delete Wishlist". This button is as below;

  <a href="/account/wishlistupdate?mainAction=delete&wishlistId=2547474" class="btn btn-danger btn-sm" onclick="return confirm('index.html')" style="" xpath="1">Delete wishlist</a>   

This button click opens a browser notification.

I have tried alert.accept(), but doesn't work for me.

 public HomePage editWishlist(){
    click(edit_button);    //     By edit_button = By.xpath("//div[@class='btn-edit-text']");
    click(deleteWishlist_button); //    By deleteWishlist_button = By.linkText("Delete wishlist");
    try {
    } catch(InterruptedException e) {
        System.out.println("got interrupted!");
    Alert alert = driver.switchTo().alert();
    return this;

How can I manage this?


This is a Javascript Confirmation Alert and you can accept it by switching to it and then accepting it:


Similarly to click on cancel you can call method dismiss()