Method: Capybara::Session#switch_to_window

Defined in:
lib/capybara/session.rb

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

Returns window that has been switched to

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:

  • (Capybara::ScopeError)

    if this method is invoked inside `within` or `within_frame` methods

  • (ArgumentError)

    if both or neither arguments were provided



481
482
483
484
485
486
487
488
489
490
491
# File 'lib/capybara/session.rb', line 481

def switch_to_window(window = nil, **options, &window_locator)
  block_given = block_given?
  raise ArgumentError, "`switch_to_window` can take either a block or a window, not both" if window && block_given
  raise ArgumentError, "`switch_to_window`: either window or block should be provided" if !window && !block_given
  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