Ruby 如何将对象的父对象建立为页面对象中的对象?

Ruby 如何将对象的父对象建立为页面对象中的对象?,ruby,page-object-gem,Ruby,Page Object Gem,在页面对象文件中: class ThisPage include PageObject 我可以建立这样一个对象: div(:user_dialog, :class => 'ud_dialog') on(ThisPage).div_elements(:text => 'Are you sure you want to do this action?').first.parent.html div(:user_dialog, parent(:text => 'Are yo

在页面对象文件中:

class ThisPage
  include PageObject
我可以建立这样一个对象:

div(:user_dialog, :class => 'ud_dialog')
on(ThisPage).div_elements(:text => 'Are you sure you want to do this action?').first.parent.html
div(:user_dialog, parent(:text => 'Are you sure you want to do this action?'))
但是,在网站的域中,有许多窗口带有
:class=>“ud\u dialog”
,在各种工作流中弹出

我可以在绑定中找到对象。像这样撬动

div(:user_dialog, :class => 'ud_dialog')
on(ThisPage).div_elements(:text => 'Are you sure you want to do this action?').first.parent.html
div(:user_dialog, parent(:text => 'Are you sure you want to do this action?'))
如何在页面文件中建立这样的窗口

i、 e.是否有如下语法:

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

对于复杂的定位器,例如定位父图元,可以使用块获取图元

如果将页面对象中的div定义为:

div(:user_dialog){
  div_elements(:text => 'Are you sure you want to do this action?').first.parent
}
然后,您的页面可以执行以下操作:

on(ThisPage).user_dialog_element.html
请注意,由于您需要第一个匹配的div,因此可以将其简化为:

div(:user_dialog){
  div_element(:text => 'Are you sure you want to do this action?').parent
}
通过使用多个定位器(取决于您的html是什么),也可能更直接。您可以找到具有ud_dialog类且包含指定文本的div(部分匹配,因为可能存在其他文本):


这是什么语言和/或平台?Ruby?最好添加语言名称标签,这样该语言的其他用户就更有可能看到这个问题。我给你加的,谢谢。我试试这个。在哪里可以找到这些信息(以及更多类似的信息)?文档和经验是我唯一的想法。阅读Cheezy(他是gem的创始人)的博客和书也可能有所帮助。