详细信息元素的页面对象访问器是什么
What is the page object accessor for a details element
我正在尝试使用 Watir 单击一个元素,但我不确定调用的页面对象访问器是什么。我几乎测试了所有这些。
这是我点击元素时显示的HTML:
<details open>
<summary>Search your employers</summary>
如果我还没有点击它,HTML 是:
<details>
<summary>Search your employers</summary>
我知道如何让脚本点击页面元素,但我不知道如何定义这个页面对象访问器。我猜我会通过调用类似的东西来识别它:
[pageobject](:test, :name => 'Search your employers')
您要找的实际上是 accessor。页面对象是代表页面的class。访问器是帮助创建与页面上的元素交互的方法的方法。
由于元素是details
元素,所以要使用相应的访问器,也称为details
。有时查看 source code 会有所帮助,因为基本元素的访问器没有出现在文档中。
根据您提供的内容,您的页面对象和访问器可以定义为:
class MyPage
include PageObject
details(:test, text: 'Search your employers')
end
但是,这假设 details
元素的文本正好是 "Search your employers"。这不太可能是真的,因为 details
元素的要点是具有 shown/hidden.
的附加元素
如果起始文本足够独特,您可以这样做:
details(:test, text: /^Search your employers/)
虽然需要更多工作,但我更愿意更具体地查找包含具有指定文本的 summary
元素的 details
元素。这可以使用 block
:
details(:test) { summary_element(text: 'Search your employers').parent }
或使用 XPath:
details(:test, xpath: '//details[./summary[text() = "Search your employers"]]')
我正在尝试使用 Watir 单击一个元素,但我不确定调用的页面对象访问器是什么。我几乎测试了所有这些。
这是我点击元素时显示的HTML:
<details open>
<summary>Search your employers</summary>
如果我还没有点击它,HTML 是:
<details>
<summary>Search your employers</summary>
我知道如何让脚本点击页面元素,但我不知道如何定义这个页面对象访问器。我猜我会通过调用类似的东西来识别它:
[pageobject](:test, :name => 'Search your employers')
您要找的实际上是 accessor。页面对象是代表页面的class。访问器是帮助创建与页面上的元素交互的方法的方法。
由于元素是details
元素,所以要使用相应的访问器,也称为details
。有时查看 source code 会有所帮助,因为基本元素的访问器没有出现在文档中。
根据您提供的内容,您的页面对象和访问器可以定义为:
class MyPage
include PageObject
details(:test, text: 'Search your employers')
end
但是,这假设 details
元素的文本正好是 "Search your employers"。这不太可能是真的,因为 details
元素的要点是具有 shown/hidden.
如果起始文本足够独特,您可以这样做:
details(:test, text: /^Search your employers/)
虽然需要更多工作,但我更愿意更具体地查找包含具有指定文本的 summary
元素的 details
元素。这可以使用 block
:
details(:test) { summary_element(text: 'Search your employers').parent }
或使用 XPath:
details(:test, xpath: '//details[./summary[text() = "Search your employers"]]')