Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda