Something strange is happening here. When I manually test this, I click the delete button, wait for the popup to appear https://i.sstatic.net/6PMS4.png and then click OK to remove the record successfully. However, when I attempt the same process in Java/Selenium, the outcome is different-
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 methods result in the OK/Cancel popup appearing briefly before disappearing.
This is the code for the delete 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 userDelete function
function userDelete() {
if (confirm("Are you sure you wish to delete this user?")) {
return true;
}
else {
return false;
}
}
I have also tested this in Edge and encountered the same issue, ruling out a Chrome-specific problem.
If anyone has any insights into what might be causing this, please let me know.
Further testing reveals the following: I set a breakpoint just before the script clicks the delete button and run the script. The page loads as expected, but then I encounter the issue.
When I manually click the Delete button, the popup appears and remains visible until I interact with it.
When stepping through the code, the popup appears briefly and then disappears.
_driver.findElement(By.id("ctl00_cpContentLeft_btnDelete")).click();
When using this code, the result is the same as in #2.
_driver.findElement(By.id("ctl00_cpContentLeft_btnDeletePatient")).sendKeys(Keys.SPACE);
Lastly, I attempt a double click, but nothing happens. In all tests, no errors are reported in the console.