1

Now before I start getting scolded, I DID read through most of the existing questions about this and applied different solutions (which mostly repeat the same thing), but it still does not work for me. I have a maven project with all necessary dependencies, and the website in testing is done specifically for IE and requires me to have a specific certificate in order to access it. I have the certificate for it, and when I go onto the website, before it loads the page it asks me to confirm that I have the certificate and I need to confirm on the pop-up window, THEN the login page fully loads. The image shows the page before I accept the certificate

The page loaded after I accept the certificate manually

NetBeans Persisting Error message

I have done to typical:

WebDriverWait wait = new WebDriverWait(driver, 3);
try {
    // Handle alert box
    driver.navigate().to("https://ke.m-pesa.com/ke/");
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
} 
catch(Exception e) {
    //whatever
}

Can you tell me where I am going wrong? So far I have used only Selenium RC up till now so this webdriver stuff is still kind of new to me. Please tell me if you need any more info I need to provide. Why do I still get the UnhandledAlertException?? and why can't I access the login page until I manually press the OK button?

3
  • I simply don't think the certificate window is an alert window. Commented Jan 16, 2015 at 14:33
  • What would you classify it as instead? Commented Jan 16, 2015 at 14:35
  • 3
    By saying, "It's not an alert window," what is really meant is that, "WebDriver can't recognize it as a window it can manipulate." The Alert interface is designed to handle only the dialogs generated by the JavaScript alert(), confirm(), and prompt() functions. Commented Jan 16, 2015 at 18:58

1 Answer 1

3

Did you try using Robot? Something like :

     Alert alert = driver.switchTo().alert();
     Robot a = new Robot();
     a.keyPress(KeyEvent.VK_ENTER);

Why robot and not Actions

From this answer :

There is a huge difference in terms of how do these tools work. Selenium uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").

Java AWT Robot uses native system events to control the mouse and keyboard.

If you are doing browser automation, ideally, you don't ever use things like Robot since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot -

Sign up to request clarification or add additional context in comments.

2 Comments

Nice, weren't familiar with that. How is that different from the Actions class?
@StasS Didn't see you asked the question :). I leave that here for information. Thanks for asking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.