5

I have the following html saved with the save_and_open_page command right before the capybara selectors are run (I've also checked page.body, it's the same): https://gist.github.com/davidkovaccs/8991af5bed1805277f52

I get the following error message: 'expected to find xpath "//div[@class='box']" 9 times, found 6 matches: "box_2001 attrkulcs1: attrvalue 1 attrkulcs2: attrvalue 2 attrkulcs3: attrvalue 3", "box_2002 attrkulcs1: attrvalue 1 attrkulcs2: attrvalue 2 attrkulcs3: attrvalue 3 attrkulcs4: attrvalue 4", "box_2003", "box_1001", "box_1002 attrkulcs1: attrvalue 1 attrkulcs2: attrvalue 2 attrkulcs3: attrvalue 3", "box_1003 attrkulcs1: attrvalue 1". Also found "", "", "", which matched the selector but not all filters. (Capybara::ExpectationNotMet)'

Note that the found 6 matches is not 6 for every test run. it a number between 4 and 9. I don't really understand what can be the 'matched the selector but not all filters' statement. As I know I'm not using any filters.

I've tried the following selectors, but all of them gives the same error message:

have_xpath("//div[@class='box']", :count => 9)
have_selector(:css, '.box', :count => 9)
have_css('.box', :count => 9)

I've tried it with capybara 2.2.1 and 2.3.0 also. I'm using Selenium webdriver 2.42.0

Running $x("//div[@class='box']").length from browser console works perfectly.

1 Answer 1

10

I'm copying twalpole's answer from github (https://github.com/jnicklas/capybara/issues/1326):

"You are actually using filters count and visible (defaults to true) without the relevant css it's impossible to say for sure, however the three empty sets of quotes would tend to indicate that 3 of the .box elements weren't actually visible on the page"

Indeed this was the problem, I've had to add a 'visible: false' parameter to my selectors to search for the elements that cannot be seen in the screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.