0

I am trying to automate a scenario where I am encountering a window modal dialog box. Please let me know how to automate this situation? I just want to know how to click the highlighted OK button on the popup appearing? Please suggest

enter image description here

4 Answers4

1

Try this

driver.switchTo().alert().accept();
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
1

You can also send keyboard events to press enter key as soon as pop up is active Pressing enter key is as equivalent as clicking OK button

Make use of Robot class in java

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER)
Ankit Agrawal
  • 257
  • 1
  • 12
  • Tried by implementing Robot class but its not working here – Prashant1992 Jan 10 '19 at 13:28
  • 1
    try adding delay statements in between `Robot r = new Robot();` `r.delay(500);` `r.keyPress(KeyEvent.VK_ENTER);` `r.delay(500);` `r.keyRelease(KeyEvent.VK_ENTER)` `r.delay(500);` – Ankit Agrawal Jan 14 '19 at 08:19
0

You can try this by using JavascriptExecutor. It always works if we fail to find element using findelement method

Dish
  • 117
  • 8
0

I just found a way to handle this issue.

DesiredCapabilities dc = new DesiredCapabilities();

dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);

d = new FirefoxDriver(dc);

then implemented the alert code in try catch block

try
    {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        System.out.println("Alert data: " + alertText);
        alert.accept();
    }
    catch (UnhandledAlertException e)
    {
        e.printStackTrace();
    }