can there be a divs method in PageObject::Accessors and is my workaround ok?

page-object-gem

Solution

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!

Problem

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...

Original source