Use Capybara commands inside an IFRAME

If you need to follow links, click buttons, etc. using Capybara inside an <iframe>, you can do it like this:

page.within_frame('iframe-id') do
  fill_in 'E-mail', with: ''
  fill_in 'Password', with: 'secret'
  click_button 'Submit'

Instead of the frame's [id] attribute you may also pass a Capybara::Node for an <iframe>.

If you're also using Cucumber you could make a meta-step like this:

When /^(.*?) inside the (.*?) frame$/ do |step_text, frame_id|
  page.within_frame(frame_id) do
    step step_text

This way you can use your existing steps Archive like this:

When I fill in "E-mail" with "" inside the login frame

Note: Spreewald >= 4.1.0 already includes that step Archive

Henning Koch almost 7 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more