Firstable, I would like to apologize for my english, I'll try my best to be as clear as possible.
I encounter a problem with Selenium, in Java. Indeed, I use a portal, and I need to be logged in to be able to browse on it. Each time I open this portal, I have to connect, a pop-up window appears. I have to use a specific account to do a specific action, and then I have to disconnect from this account and reconnect with another account to manage some things. I am able to close the pop-up which appears when I click on the “disconnect” button with a robot, with the “Enter” key. And then, I am blocked. The window disappears, ok, but the program crashes and tells me this error: “Modal dialog present: Demande de confirmation - Confirmez-vous la fermeture du portail ?” After this step, I can’t even open the portal again. I have also a connection matter, in fact the browser reminds my user and password, but I need to change account. So I thought about erasing cookies. I am a bit lost.
My code is :
driver.findElement(By.id("disconnectBtn")).click();
WaitUtils.waitFor(5000);
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
WaitUtils.waitFor(5000);
driver.manage().deleteAllCookies();
System.out.println("I have deleted cookies.");
allerSurPortail("L1", driver);
System.out.println("I have opened a second time the portal.");
accueilPortailPage.fermerFrame(driver);
WaitUtils.waitFor(5000);
My function "fermerFrame" permits closing a pop-up which appears when I am connected on the website, it works.
To resume:
- My program opens the portal which shows a pop-up to connect.
- Once connected, I have to do some things on the website (things I don't do for the test)
- I click on the disconnect button, this pop-up appears Disconnect pop-up window
- I create a robot to press the Enter button to close this pop-up, so close the whole browser. Here I have this error Error Message (Is it a focus problem?)
- I would like to open the portal again and connect with another login
I have tried to catch this Error Message, but I don't understand why it's still crashing, and it doesn't enter in the catch..
driver.findElement(By.id("disconnectBtn")).click();
try {
System.out.println("Entering in the first try");
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
} catch (org.openqa.selenium.UnhandledAlertException f) {
try {
System.out.println("Entering in the second try");
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
System.out.println("Alert data: " + alertText);
alert.accept();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
} catch (NoAlertPresentException e) {
System.out.println("Entering in the second catch");
e.printStackTrace();
}
}
Thank you in advance.