4

In page object I would like to have access to multiple divs in a particular way.

This is access to the first div that matches:

div(:search_result, id: /rptSearchResults/)

This would be access to multiple divs that match if divs existed in PageObject::Accessors:

divs(:search_result, id: /rptSearchResults/)

So far I have tried:

visit_page SearchResultsPage do |page|

    #This outputs the first div that matches
    page.search_result_element.div_elements(id: /rptSearchResults/).each { |i| puts i.text }

    #This accesses the page and outputs text in all divs that match
    page.div_elements(id: /rptSearchResults/).each { |i| puts i.text}

end

Can anyone suggest a better way of doing this within page-object?

Thanks in advance...

  • There was an issue opened for this recently - see [Issue 144](https://github.com/cheezy/page-object/issues/144) – Justin Ko Dec 01 '12 at 01:27

1 Answers1

6

By using the way you defined multiple divs, divs(:search_result, id: /rptSearchResults/), you can access the elements by search_result_elements.

Some examples:

  • Get the first div element - search_result_elements[0]
  • Get the length of elements returned - search_result_elements.length
  • Get the texts of the divs - search_result_elements.map(&:text)
  • Get a child element from the third div - search_result_elements[2].element

Hope this helps!

sheg
  • 132
  • 1
  • 8