Read more

Use Capybara commands inside an IFRAME

Henning Koch
June 29, 2015Software engineer at makandra GmbH

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
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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

Posted by Henning Koch to makandra dev (2015-06-29 10:25)