Use Capybara commands inside an IFRAME

Updated . Posted . Visible to the public.

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: 'foo@bar.com'
  fill_in 'Password', with: 'secret'
  click_button 'Submit'
end

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
  end
end

This way you can use your existing steps Show archive.org snapshot like this:

When I fill in "E-mail" with "foo@bar.com" inside the login frame

Note: Spreewald >= 4.1.0 already includes that step Show archive.org snapshot

Henning Koch
Last edit
Judith Roth
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2015-06-29 08:25)