I am automating an website using JBehave and Selenium Webdriver, one of the functionality is to logout the system. It works for most times, but eventually it doesn't, because the browser shows an alert saying: "Fail to disconnect" and it throws the following exception:
org.openqa.selenium.UnhandledAlertException: unexpected alert open
Is there any workaround for this?
You need to switch to the Alert first and then accept or dismiss it.
Try this-
IAlert alert = driver.SwitchTo().Alert();
//Accept Alert
alert.Accept();
//Or
//Dismiss Alert
alert.Dismiss();