Method: Capybara::Session#switch_to_frame
- Defined in:
- lib/capybara/session.rb
#switch_to_frame(element) ⇒ Object #switch_to_frame(location) ⇒ Object
Switch to the given frame.
If you use this method you are responsible for making sure you switch back to the parent frame when done in the frame changed to. #within_frame is preferred over this method and should be used when possible. May not be supported by all drivers.
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/capybara/session.rb', line 408 def switch_to_frame(frame) case frame when ::Node::Element driver.switch_to_frame(frame) scopes.push(:frame) when :parent if scopes.last != :frame raise ::ScopeError, "`switch_to_frame(:parent)` cannot be called from inside a descendant frame's " \ '`within` block.' end scopes.pop driver.switch_to_frame(:parent) when :top idx = scopes.index(:frame) top_level_scopes = [:frame, nil] if idx if scopes.slice(idx..).any? { |scope| !top_level_scopes.include?(scope) } raise ::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's " \ '`within` block.' end scopes.slice!(idx..) driver.switch_to_frame(:top) end else raise ArgumentError, 'You must provide a frame element, :parent, or :top when calling switch_to_frame' end end |