1
votes

I've pored over the capybara cheat sheet, a many SO posts, trying all the options to find a unique class for a div, compare its text to a value but it cannot find this class. There are several values but it ought to be finding them but coming up invalid.

feature/items_spec.rb

            page.find(:css, "item_hiscore "+"item-#{@item_2.id} "+"small-6 "+"columns", :visible => true).text == ("/ " + "#{@item_2.high_score}")

yields =>

 Failure/Error: page.find(:css, "item_hiscore "+"item-#{@item_2.id} "+
 "small-6 "+"columns", :visible => true).text == ("/ " + "#{@item_2.high_score}")
 Capybara::ElementNotFound:
   Unable to find css "item_hiscore item-2 small-6 columns"

The page source is:

 <div class="item_hiscore item-2 small-6 columns">
                    / 10
                </div>

Should I paste in my previous efforts to show all the options I've tried? Thanks for your time, sam

1

1 Answers

3
votes

Your css selector is looking for a columns element:

<item_hiscore>
  <item-2>
    <small-6>
      <columns>

Classes are located by using a .. Spaces mean to look within a node.

To find your element by all of the classes, you can do:

page.find(:css, ".item_hiscore.item-#{@item_2.id}.small-6.columns", :visible => true)