Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir Webdriver how to close child windows

I'm in the process of migrating some of our legacy Watir scripts over to Watir-Webdriver. The migration has gone mostly well except for how they designed Watir-Webdriver to handle popup windows. Rather than using the tried-and-true 'Attach' method, they have replaced it with a simplified 'Window' method. The syntax is quite simple, however I am having a difficult time understand how to close a separate child window without closing the parent window. Currently my code is something like this -

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

Currently what is happening is that the b.close method is closing both the child window and 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 the 'PREVIEWBUTTON' indeed creates a child window, but I need the parent window to stay open.

like image 336
Brian Avatar asked Aug 06 '12 21:08

Brian


1 Answers

Try this:

b.window(:title, POPUPWINDOW).close
like image 80
Željko Filipin Avatar answered Oct 05 '22 19:10

Željko Filipin