How to close Watir Webdriver child windows

Now I am transferring some of our old Watir scripts to Watir-Webdriver. The migration went mostly well, except for how they developed Watir-Webdriver to handle pop-ups. Instead of using the proven Attach method, they replaced it with the simplified Window method. The syntax is pretty simple, but it's hard for me to figure out how to close a separate child window without closing the parent window. My code currently looks something like this:

  b.button(:xpath => PREVIEWBUTTON).click
  b.window(:title, POPUPWINDOW).use DO
    b.close
  end

What is currently happening is that the b.close method closes the child window and the parent window. I'm not sure why this is happening since the b.close method is contained in the DO block. I need to verify that "PREVIEWBUTTON" does indeed create a child window, but I need the parent window to remain open.

+5
source share
1 answer

Try the following:

b.window(:title, POPUPWINDOW).close
+9
source

All Articles