On the login page that I am trying to automate, generates a pop-up for invalid login credentials. I am using a try, catch block to switch control to alert message and check whether the alert pops or not in order to decide between successful and unsuccessful login. Below is the function I am using for this purpose:
public alertChecker isAlertPresent(WebDriver driver)
{
alertChecker acObj = new alertChecker();
try{
Alert alt = driver.switchTo().alert();
acObj.sAlertMessage = alt.getText(); // get content of the Alter Message
acObj.bAlertPresent = true;
alt.accept();
}
catch (NoAlertPresentException Ex)
{
acObj.bAlertPresent = false;
acObj.sAlertMessage = "";
}
return acObj;
}
I have 4 inputs, 1st has valid credentials and remaining are invalid. I am able to run the test for one valid followed by another 2 invalid combinations. While running the test for last set of credentials, I am getting below error:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status from unexpected alert open
I am using Chrome browser. Please help me resolve this