Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with ModalDialog using selenium webdriver?

I am unable to switch to Modal Dialog of given example

http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm

I don't know how to get element on modal Dialog

enter image description here

like image 838
Jasmine.Olivra Avatar asked Dec 18 '12 15:12

Jasmine.Olivra


People also ask

How can we handle window based pop up using Selenium?

Selenium uses the getWindowHandles () and getWindowHandle () methods to work with child windows. The getWindowHandles () method contains all the window handle ids of the opened windows. The window id handles are held in the form of Set data structure [containing data type as String].


2 Answers

Use

following methods to switch to modelframe

driver.switchTo().frame("ModelFrameTitle");

or

driver.switchTo().activeElement()

Hope this will work

like image 114
Arun Avatar answered Sep 18 '22 17:09

Arun


What you are using is not a model dialog, it is a separate window.

Use this code:

private static Object firstHandle;
private static Object lastHandle;

public static void switchToWindowsPopup() {
    Set<String> handles = DriverManager.getCurrent().getWindowHandles();
    Iterator<String> itr = handles.iterator();
    firstHandle = itr.next();
    lastHandle = firstHandle;
    while (itr.hasNext()) {
        lastHandle = itr.next();
    }
    DriverManager.getCurrent().switchTo().window(lastHandle.toString());
}

public static void switchToMainWindow() {
    DriverManager.getCurrent().switchTo().window(firstHandle.toString());
like image 42
Amit Kapoor Avatar answered Sep 21 '22 17:09

Amit Kapoor