Rails + Cucumber/Selenium/Capybara: Compare the text values of two h4s with the same class? -


i have 2 <h4>s surround name of search result. need compare values of first , last results make sure in alphabetical order. h4's have class of search-result-name. both in same form tag id #search-results.

this broken cucumber test:

then(/^the results should alphabetical$/)   first_product_name = page.all('.search-result-name')[1] #first('.search-result-name').text   last_product_name = page.all('.search-result-name')[2]   first_product_name[0].should <= last_product_name[0] end 

this giving me error undefined method '[]' nil:nilclass (nomethoderror), i'm thinking i'm doing find incorrectly. can't find documentation on how find 2nd, 3rd, etc matches of element. thing both in same div , have same class. how use selenium/capybara it?

use mighty xpath. //form/h4[@class="search-result-name"][1] refers first h4 node,
similarly, //form/h4[@class="search-result-name"][2] refers second h4 node

capybara actively supports finding , querying xpath.
don't have complete knowledge dom, based on inputs, above must work. modify per own. :)


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -