Echographia

making things better, making better things

Thursday, January 13, 2011

“Element not found in the cache”

I was getting the above error, intermittently, from Selenium/WebDriver via Cucumber/Capybara. My code looked something like this:

When /^I wait for the popup to close$/ do
  wait_until { !page.find('#nyroModalContent').try(:visible?) }
end

What’s happening, I think, is this:

  1. Capybara asks Selenium for a handle to the #nyroModalContent element.
  2. Selenium, after returning it, gets the response from my server that tells it to close the popup.
  3. Capybara asks Selenium, hey, that element you just gave me a handle to? Is it still visible?
  4. Selenium is all, “What element?”

For my present purposes, it turns out I don’t need the “visible” check, so I could just do this:

  wait_until { page.has_no_css?('#nyroModalContent') }

If I had needed to get the element and then act on it, though, I think the way to do it would be to write JavaScript that performs both actions, and call it with page.evaluate_script.

[Ran across John Nunemaker's exhortation to "clog it before you forget it."]

posted by erik at 11:25 am  

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress