2

In a page object file:

class ThisPage
  include PageObject

I can establish an object like this:

div(:user_dialog, :class => 'ud_dialog')

However, in the domain of the website, there are many windows with :class => 'ud_dialog' that popup in various workflows.

I can get to the object in binding.pry like this:

on(ThisPage).div_elements(:text => 'Are you sure you want to do this action?').first.parent.html

How can I establish the window like this in the page file?

i.e. is there some syntax like this:

div(:user_dialog, parent(:text => 'Are you sure you want to do this action?'))
4

1 回答 1

2

For complex locators, such as locating the parent element, you can use a block to get the element.

If you define the div in your page object as:

div(:user_dialog){
  div_elements(:text => 'Are you sure you want to do this action?').first.parent
}

Then your page can do:

on(ThisPage).user_dialog_element.html

Note that since you want the first matching div, you could simplify it to:

div(:user_dialog){
  div_element(:text => 'Are you sure you want to do this action?').parent
}

It might also be possible to be more direct by using multiple locators (depending on what your html is). You could locate the div that has the ud_dialog class and contains the specified text (a partial match since there is likely other text):

div(:user_dialog, :class => 'ud_dialog', 
  :text => /Are you sure you want to do this action?/)
于 2014-01-03T01:53:37.353 回答