0

I'm trying to click on a pop-up alert message on a UI with Selenium Webdriver.

The problem is, it is not clicking on accept or cancel even if I explicitly and implicitly wait. Is there any other alternative to clicking on a pop-up message. I tried to send key by Robot and press enter, but it did not work too.

click ok popup message function:

    try {
            WebDriverWait wait = new WebDriverWait(driver, 40);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert alert = driver.switchTo().alert();
            report.log(LogStatus.INFO, "Displayed Pop-up Window Alert Message ->  " + alert.getText() + " for the Field -> " + fieldName);
            System.out.println("Displayed Pop-up Window Alert Message ->  " + alert.getText() + " for the Field -> " + fieldName);
            alert.accept();
            Thread.sleep(3000);
        } catch (NoAlertPresentException ex) {
            System.err.println("Error came while waiting for the alert popup. ");
            report.log(LogStatus.INFO, "Alert pop up box is NOT populating when user clicks on: ");
        }

this is what the html looks like for the popup:

<input type="submit" name="ctl00$ctl00$Content$ContentPlaceHolderMain$Continue" value="Continue..." 
            onclick="if(warnOnDelete('ctl00_ctl00_Content_ContentPlaceHolderMain_EditRadioOptions_1',"
                    + "'Please confirm if you wish to delete.') == false) return false;" 
                    id="ctl00_ctl00_Content_ContentPlaceHolderMain_Continue" style="width:100px;">

It has to be in IE, we are not allow to use anything except IE

Update: function for the confirm boxes


        function warnOnDelete(deleteButtonID, msg) {
            var deleteRadioButton = document.getElementById(deleteButtonID);
            if (deleteRadioButton != null) {
                if (deleteRadioButton.checked == true)
                    return confirm(msg);
            }
            return true;
        }

bubbles2189
  • 149
  • 1
  • 2
  • 15

1 Answers1

0

Seems the element is not an Alert but an <input> element and to click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[id$='_Content_ContentPlaceHolderMain_Continue'][value^='Continue'][name$='Continue']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(@id, '_Content_ContentPlaceHolderMain_Continue') and starts-with(@value, 'Continue')][contains(@name, 'Continue')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • But on the UI, I get a popup saying are you sure you want to delete with an option for OK and Cancel. How would I click either of those – bubbles2189 Jun 14 '19 at 12:46
  • @bubbles2189 You have given us the HTML which you wanted to click and my solution is how you need to click the element. I am not sure about the **OK** and **Cancel** button you are speaking of. Did my answer work for you for the the question you have asked? – undetected Selenium Jun 14 '19 at 12:50
  • I have added the javascript function for the confirm message, my question above states "'I'm trying to click on a pop-up alert message" – bubbles2189 Jun 14 '19 at 12:55