问题
I'm on ruby using the page-object-gem by cheezy. Following the excellent answer here, I decided to ask this question (a page_section
isn't an element I think). Anyway what is the syntax for the dynamic finder/locator for a page_section
and page_sections
?
回答1:
I do not believe this scenario was considered in the original design, so there is not great support. Feel free to request it at https://github.com/cheezy/page-object/issues .
That said, you could use the internal platform
object's #page_for
and #pages_for
methods. The parameters are:
- A Hash for locating the container elements.
- The page section class.
Example:
class Container
include PageObject
end
class MyPage
include PageObject
# Individual page section
def container
platform.page_for({tag_name: 'div'}, Container)
end
# Collection of page sections
def containers
platform.pages_for({tag_name: 'div'}, Container)
end
end
来源:https://stackoverflow.com/questions/59164940/cheezy-dynamic-finder-for-page-section