Module: Watir::HasWindow

Included in:
Browser
Defined in:
lib/watir/has_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_windowWindow

Returns original window if defined, current window if not See Window#use

Examples:

browser.window(title: 'closeable window').use
browser.original_window.use

Returns:



48
49
50
# File 'lib/watir/has_window.rb', line 48

def original_window
  @original_window ||= window
end

Instance Method Details

#switch_windowWindow

Waits for and returns second window if present See Window#use

Examples:

browser.switch_window

Returns:

Raises:

  • (StandardError)


62
63
64
65
66
67
68
69
70
# File 'lib/watir/has_window.rb', line 62

def switch_window
  current_window = window
  wins = windows
  wait_until { (wins = windows) && wins.size > 1 } if wins.size == 1
  raise StandardError, 'Unable to determine which window to switch to' if wins.size > 2

  wins.find { |w| w != current_window }.use
  window
end

#window(opts = {}, &blk) ⇒ Window

Returns browser window.

Examples:

browser.window(title: 'closeable window')

Returns:



29
30
31
32
33
34
35
# File 'lib/watir/has_window.rb', line 29

def window(opts = {}, &blk)
  win = Window.new self, opts

  win.use(&blk) if blk

  win
end

#windows(opts = {}) ⇒ Array<Window>

Returns browser windows array.

Examples:

browser.windows(title: 'closeable window')

Returns:



16
17
18
# File 'lib/watir/has_window.rb', line 16

def windows(opts = {})
  WindowCollection.new self, opts
end