How to deal with ModalDialog using selenium webdriver?

后端 未结 8 1750
天命终不由人
天命终不由人 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:21

    I have tried it, it works for you.

    String mainWinHander = webDriver.getWindowHandle();
    
    // code for clicking button to open new window is ommited
    
    //Now the window opened. So here reture the handle with size = 2
    Set handles = webDriver.getWindowHandles();
    
    for(String handle : handles)
    {
        if(!mainWinHander.equals(handle))
        {
            // Here will block for ever. No exception and timeout!
            WebDriver popup = webDriver.switchTo().window(handle);
            // do something with popup
            popup.close();
        }
    }
    

提交回复
热议问题