“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:
- Capybara asks Selenium for a handle to the #nyroModalContent element.
- Selenium, after returning it, gets the response from my server that tells it to close the popup.
- Capybara asks Selenium, hey, that element you just gave me a handle to? Is it still visible?
- 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."]
Comments Off