Could there be a divs method in PageObject :: Accessors and is this my workaround?

In the page object, I would like to have access to several divs in a certain way.

This is access to the first div, which corresponds to:

div(:search_result, id: /rptSearchResults/) 

This will access multiple divs that match if divs exist 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 to do this inside the page-object?

Thanks in advance...

+4
source share
1 answer

Using the way you defined multiple divs(:search_result, id: /rptSearchResults/) , divs(:search_result, id: /rptSearchResults/) , you can access the elements with search_result_elements .

Some examples:

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

Hope this helps!

+6
source

Source: https://habr.com/ru/post/1442132/


All Articles