multiple modal dialog boxes, unable to select the top most one multiple modal dialog boxes, unable to select the top most one selenium selenium

multiple modal dialog boxes, unable to select the top most one


Robot API can be used to get handle topmost modal box if there is an issue with switching to frame.

To use Robot API, give the following line of codes

Robot key = new Robot();key.keyPress(KeyEvent.VK_ENTER); key.keyRelease(KeyEvent.VK_ENTER);

Make sure that the control is already on the intended button. If the focus is on another button on the modal, then give 'tab' or other keyevent to get the control on the update button.


I have taken a break of a couple of months from automation. I happened to be doing some maintenance on my scripts and found the root cause of this problem.

The issue was not with my code, the code was fine just i forgot one crucial step. During the business process a second window was opened which required user input. I used the code to switch to this popup window.:

public void get_window_ids(){    //Get the handles for the main window and the popup window for the upload button            try {                Set<String> AllWindowHandles = driver.getWindowHandles();                System.out.println(AllWindowHandles.size()+  " distinct windows: " + AllWindowHandles);                window1 = (String) AllWindowHandles.toArray()[0];                System.out.println("\nwindow 1 is " + window1+"\n");                window2 = (String) AllWindowHandles.toArray()[1];                System.out.println("\nwindow 2 is " + window2+"\n");            } catch (Exception e) {                // TODO Auto-generated catch block                e.printStackTrace();            }}public String getWindow1() {    return window1;}public String getWindow2() {    return window2;}

When I switched to the window2 I forgot to switch back to the first window. I just missed the fact that there was a popup window I forgot about. So if you are using these modal popups remember to return control back to the main window.