2

I have an in the the page that I need to test with Cucumber and Capybara, the iframe does not have a class or id attribute but it's the only iframe on the DOM. How can I use the within_frame capybara method?

juliangonzalez
  • 4,231
  • 2
  • 37
  • 47

2 Answers2

2

use find to get the element and pass it to the within_frame method.

iframe = find('iframe')
within_frame(iframe) do
 # expect something here
end
juliangonzalez
  • 4,231
  • 2
  • 37
  • 47
1

If you're using a recent version of Capybara the locator argument to within_frame is optional if there's only one iframe on the page

within_frame do
  # blah blah
end
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • That's a nice improvement! I'm stuck with an old version, but good to know. – juliangonzalez Nov 10 '18 at 00:25
  • @juliangonzalez Depending on how old a version you're using you may just be able to pass `nil` as the locator to have it default to finding any frame `within_frame nil do ... end` or by frame index `within_frame 0 do ... end` – Thomas Walpole Nov 10 '18 at 04:42