Skip to content
skierpage edited this page Feb 12, 2014 · 4 revisions

It is possible to find elements nested within other elements. All elements have a complete set of xx_element methods which look for the named element within its own context. For example, if I want to find an unordered_list nested within a div I can do the following:

    div(:errors, :id => 'error_explanation')
    
    def error_messages
      errors_element.unordered_list_element.text
    end

This method is getting the div element and then calling the method on it to retrieve the unordered_list.
I could also find the same thing by declaration:

    div(:errors, :id => 'error_explanation')
    unordered_list(:error_messages) do |page|
      page.errors_element.unordered_list_element
    end

The generated error_messages method will find the text within the unordered_list that is within the div.