Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Selenium test - OK/Cancel popup disappearing immediately

Odd one here. When testing this manually I click the delete button, wait for the popup enter image description here Then I click OK and the record is removed as expected. But when I try to do the same in Java/Selenium it goes like this->

WebElement element = _driver.findElement(By.id("btnDeletePatient"));
JavascriptExecutor executor = (JavascriptExecutor)_driver;
executor.executeScript("arguments[0].click();", element);

or

_driver.findElement(By.id("btnDeletePatient")).click();

Both have the same response, the OK/Cancel popup will appear and then immediately vanish.

This is the code for the button

<input type="submit" name="ctl00$cpContentLeft$btnPatient" 
value="Delete User" onclick="return userDelete();" 
id="ctl00_cpContentLeft_btnPatient" 
tabindex="81" class="btn btn-outline-primary btn-sm mr-3">

And this is the code for the function userDelete

 function userDelete() {
        if (confirm("Are you sure you wish to delete this user?")) {
            return true;
        }
        else {
            return false;
        }
    }

Also I have now tried the same in Edge, same thing so this does not appear to be a Chrome issue.

Anyone got any ideas what is causing this please?

Further tests as follows. I place a breakpoint just at the point the script will click the delete run and run the script. The page loads as expected and I get to the problem point.

  1. I manually click the Delete button, the popup appears and then stays until I click cancel.

  2. Using this code I step through and the popup appears and then instantly disappears.

    _driver.findElement(By.id("ctl00_cpContentLeft_btnDelete")).click();

  3. Using this code the response is the say as 2.

    _driver.findElement(By.id("ctl00_cpContentLeft_btnDeletePatient")).sendKeys(Keys.SPACE);

  4. Then I try a double click and nothing happens. On all tests I see no errors in the console.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I hope you are clicking the delete button before page loads completely, that is why pop is disappearing suddenly. please add wait before clicking delete button.

Steps:

  1. Load the page completely (add wait here)
  2. Click the delete button
  3. click Okay button.

please add some more codes here and screenshots too. that would be more helpful

about 4 years ago · Juan Pablo Isaza Report

0

This looks like a java script alert. In selenium, we have specific way to handle alert. You do not need to click on ok. You can first wait for alert to be present. If it is present, then switch to that alert.

Then, We have specific methods to handle alerts in selenium.

alert.accept() clicks on ok.

alert.dismiss() clicks on cancel.

Sample code from selenium documentation:

driver.findElement(By.linkText("See a sample prompt")).click();

//Wait for the alert to be displayed and store it in a variable
Alert alert = wait.until(ExpectedConditions.alertIsPresent());

//Type your message
alert.sendKeys("Selenium");

//Press the OK button
alert.accept();

//Press the Cancel button
alert.dismiss();

//Store the alert in a variable for reuse
String text = alert.getText();
about 4 years ago · Juan Pablo Isaza Report

0

Ok found it

The issue was within the chromedriver, this line fixed it

chromeOptions.setCapability("unexpectedAlertBehaviour", "ignore");

Now the popup remains until actioned in the script.

We live and learn, thanks for all your help.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!