Sha256: 72614fcc125bd1aba3bdf98705e141ae1f81c1a49948ac70dfb00ba0d7dab292

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

require 'watir/ie'

module Watir
  class IE
    # close all ie browser windows
    def self.close_all
      close_all_but nil
    end
    # find other ie browser windows and close them
    def close_others
      IE.close_all_but self
    end
    private
    def self.close_all_but(except=nil)
      Watir::IE.each do |ie|
        ie.close_modal
        ie.close unless except and except.hwnd == ie.hwnd
      end
      sleep 1.0 # replace with polling for window count to be zero?
    end
    public
    # close modal dialog. unlike IE#modal_dialog.close, does not wait for dialog
    # to appear and does not raise exception if no window is found.
    # returns true if modal was found and close, otherwise false
    def close_modal
      begin
        original_attach_timeout = IE.attach_timeout
        IE.attach_timeout = 0
        self.modal_dialog.close
        true
      rescue NoMatchingWindowFoundException, Wait::TimeoutError
        false
      ensure
        IE.attach_timeout = original_attach_timeout
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
watir-1.9.0.rc4 lib/watir/close_all.rb
watir-1.9.0.rc3 lib/watir/close_all.rb
watir-1.9.0.rc2 lib/watir/close_all.rb
watir-1.9.0.rc1 lib/watir/close_all.rb
watir-1.8.1 lib/watir/close_all.rb
watir-1.8.1.rc1 lib/watir/close_all.rb
watir-1.8.0 lib/watir/close_all.rb
watir-1.8.0.rc1 lib/watir/close_all.rb
watir-1.7.1 lib/watir/close_all.rb
watir-1.7.0 lib/watir/close_all.rb
watir-1.7.0.rc1 lib/watir/close_all.rb