1

In a Capybara feature spec, I am attempting to do the following:

  within_frame("element_content_content_ifr") do
    # do stuff
  end

Where element_content_content_ifr is the CSS ID of my tinymce iframe.

I get the error:

Capybara::ElementNotFound:
       Unable to find visible frame "element_content_content_ifr"

I've set a pause during the test and inspected element. The iframe with the specified ID is definitely there, but Capybara can't find it. I am not having issues with Capybara finding iframes in other parts of my application, only the TinyMCE iframe.

I have also attempted sleep 5 before executing the within_frame line, but I get the same error. Is there something I'm doing wrong? Is there a proper way to do Capybara tests when TinyMCE is on the page?

Attached is a screenshot of the iframe's visibility on the page, as well as its DOM ancestors: screenshot of DOM elements

ianrandmckenzie
  • 472
  • 3
  • 12
  • 1
    Are you sure the "element_content_content_ifr" iframe isn't nested inside another iframe? Also does the iframe have any size on the page? If those pointers don't lead to an answer - add the relevant HTML or screen shot of DOM inspection. – Thomas Walpole Aug 08 '19 at 20:45
  • The iframe is definitely not within another iframe, although it is within a form, does that affect anything? The size is an interesting question. I'm not sure it has a size when there isn't any content, but there is when content is entered. Thanks for the lead, I'll let you know if it brings me to a solution. – ianrandmckenzie Aug 08 '19 at 20:50
  • I looked into it and the iframe is 936x156 (based on device's current size), so the iframe definitely should be visible. – ianrandmckenzie Aug 08 '19 at 20:54
  • Please add the HTML or a screenshot of the DOM inspection showing the iframe and its ancestors – Thomas Walpole Aug 08 '19 at 20:55
  • Also - make sure you're not calling the `within_frame` while you're scoped to an element that doesn't contain the iframe (if you are scoped). – Thomas Walpole Aug 08 '19 at 20:56
  • @ThomasWalpole see updated post. Re: scoping, it is not currently scoped in anything. – ianrandmckenzie Aug 08 '19 at 20:59
  • Hmmm -- there's an ancestor div with `visibility: hidden' style -- It's possible that's screwing up the visibility algorithm – Thomas Walpole Aug 08 '19 at 21:00
  • That's definitely a strong lead. Will have to test later, I have a meeting in 4 minutes! – ianrandmckenzie Aug 08 '19 at 21:11
  • Looking at the HTML and CSS that's shown in the screenshot I'm actually really confused as to why the iframe is visible at all -- maybe some kind of interaction between visibility and flexbox or something. – Thomas Walpole Aug 08 '19 at 21:45

1 Answers1

1

From the HTML/CSS shown it's confusing how the iframe is shown at all since its ancestor <div role="application" ...> has visibility: "hidden" as a style and there isn't a visible override of that anywhere below. First thing would be to make sure you're running a recent version of Capybara and whatever driver you're using (I assume selenium). If you already are, or that doesn't fix the issue you can try working around it with

within_frame("element_content_content_ifr", visible: false) do

and see if that works.

Beyond that if you can figure out what CSS is making the frame actually visible while inside the hidden element, I would appreciate it if you could file an issue on the Capybara project with enough info to replicate the issue.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks, Thomas. The `visible: false` helped me move forward. I'm actually quite confused as well why I'm able to see elements that are nested in a hidden element. As far as I'm concerned, it's TinyMCE magic that I have officially run out of time investigating further. That being said, I'm more than happy to file an issue if you want me to. I wonder if this is more something that's under the wheelhouse `tinymce-rails`. – ianrandmckenzie Aug 08 '19 at 22:39