Quantcast
Channel: tech·naw·lol·geez » Ruby on Rails
Viewing all articles
Browse latest Browse all 4

Unable to find css “[element_id]” (Capybara::ElementNotFound)

$
0
0

If you are seeing this capybara error:

Unable to find css "[element_id]" (Capybara::ElementNotFound)

Make sure that you actually call visit before trying to find an element!

I was trying to use a regular capybara selector

find("element_id").should be_visible

This should have been cut and dry. Since capybara’s find() selector uses #id by default, and since my page had that specific element on it, there should not have been any issue. But no matter what I tried — more different selectors, xpaths, etc — I kept getting the same frustrating error:

Unable to find css "[element_id]" (Capybara::ElementNotFound)

I thought I was going crazy, or that I had completely lost my ability to program, or both!

My problem was that I had forgotten to call visit before calling find

As soon as I called visit, my error went away

visit '/'
find("element_id").should be_visible

This makes sense, though, right? If you don’t call visit first

There is no HTML content in which to find your element!

It would be nice if capybara had a more descriptive error when you try to call find without having first called visit. That way this type of error would not frustrate so many people for so long!

I hope this helps!


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images