Method: Capybara::Session#switch_to_frame
- Defined in:
- lib/capybara/session.rb
#switch_to_frame(element) ⇒ Object #switch_to_frame(: parent) ⇒ Object #switch_to_frame(: top) ⇒ 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. Capybara::Session#within_frame is preferred over this method and should be used when possible. May not be supported by all drivers.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/capybara/session.rb', line 386 def switch_to_frame(frame) case frame when Capybara::Node::Element driver.switch_to_frame(frame) scopes.push(:frame) when :parent if scopes.last != :frame raise Capybara::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) if idx if scopes.slice(idx..-1).any? { |scope| ![:frame, nil].include?(scope) } raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's "\ '`within` block.' end scopes.slice!(idx..-1) 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 |