Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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 only used Selenium RC up till now so this webdriver stuff is still kind of new to me. Please let me know 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?

1 Answer

0 votes
by (62.9k points)

I’d suggest you try using Robot. Use the code below:

     Alert alert = driver.switchTo().alert();

     Robot a = new Robot();

     a.keyPress(KeyEvent.VK_ENTER);

There is a huge difference in terms of how 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 also be solved with Robot.

Browse Categories

...