Odd one here. When testing this manually I click the delete button, wait for the popup 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.
I manually click the Delete button, the popup appears and then stays until I click cancel.
Using this code I step through and the popup appears and then instantly disappears.
_driver.findElement(By.id(“ctl00_cpContentLeft_btnDelete”)).click();
Using this code the response is the say as 2.
_driver.findElement(By.id(“ctl00_cpContentLeft_btnDeletePatient”)).sendKeys(Keys.SPACE);
Then I try a double click and nothing happens. On all tests I see no errors in the console.
Advertisement
Answer
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.