Capybara selectors, but not for all filters, what does this mean?

I have the following html saved with the save_and_open_page command before running the capybara selectors (I also checked page.body, this is the same thing): 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 3 attrkulcs3: attrvalue 3 attrkulcs3: attrvalue 3 attrkulcs1: attrvalue 1 attrkulcs2: attrvalue 1 attrkulcs2 . Also found "", "", "" that match the selector, but not all filters. (Capybara :: ExpectationNotMet)

Note that the 6 matches found are not equal to 6 for each test run. this number is from 4 to 9. I really do not understand what can be "consistent with the selector instruction, but not with all filters." As far as I know, I do not use any filters.

I tried the following selectors, but they all give the same error message:

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

I also tried it with capybara 2.2.1 and 2.3.0. I am using Selenium webdriver 2.42.0

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

+4
source share
2 answers

twalpole github (https://github.com/jnicklas/capybara/issues/1326):

" ( - true) css, , , 3 .box "

, , "visible: false" , .

+8

' , :

  • : "div"
  • : @ class= 'box'

, 9 div, .box.

, html ( 9 div .box)?

UPDATE:

, . "//div[@class='box']" - , - , text: 'foo' ..

, html , capybara (2.2.1), :

`` `

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

`` `

, ...

+1

Source: https://habr.com/ru/post/1543915/


All Articles