How to deal with ModalDialog using selenium webdriver?

后端 未结 8 1741
天命终不由人
天命终不由人 2020-12-01 14:33

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 kno

8条回答
  •  [愿得一人]
    2020-12-01 15:26

    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 handles = DriverManager.getCurrent().getWindowHandles();
        Iterator 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());
    

提交回复
热议问题