Method: Capybara::Session#switch_to_window

Defined in:
lib/capybara/session.rb

#switch_to_window(&block) ⇒ Capybara::Window #switch_to_window(window) ⇒ Capybara::Window

Switch to the given window.

Overloads:

  • #switch_to_window(&block) ⇒ Capybara::Window

    Switches to the first window for which given block returns a value other than false or nil. If window that matches block can't be found, the window will be switched back and WindowError will be raised.

    Examples:

    window = switch_to_window { title == 'Page title' }

    Raises:

  • #switch_to_window(window) ⇒ Capybara::Window

    Parameters:

    Raises:

Returns:

Raises:



512
513
514
515
516
517
518
519
520
521
522
# File 'lib/capybara/session.rb', line 512

def switch_to_window(window = nil, **options, &window_locator)
  raise ArgumentError, '`switch_to_window` can take either a block or a window, not both' if window && window_locator
  raise ArgumentError, '`switch_to_window`: either window or block should be provided' if !window && !window_locator

  unless scopes.last.nil?
    raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from ' \
                                '`within` or `within_frame` blocks.'
  end

  _switch_to_window(window, **options, &window_locator)
end