您应该可以使用xpath。
例如,请考虑以下HTML
<ul class="ui-autocomplete" role="listbox">
<li class="ui-menu-item" role="menuitem" wicketpath="false">Value 1</li>
<li class="ui-menu-item" role="menuitem" wicketpath="false">Value 2</li>
<li class="ui-menu-item" role="menuitem" wicketpath="true">Value 3</li>
</ul>
以下XPath会给有wicketpath =真里的文字:
puts browser.li(:xpath, "//li[@wicketpath='true']").text
#=>Value 3
更新 - 可选择的解决方案 - 添加到定位器:
如果您使用很多wicketpath,可以将它添加到定位器中。
后,你需要的Watir-webdriver的,补充一点:
# This allows using :wicketpath in locators
Watir::HTMLElement.attributes << :wicketpath
# This allows accessing the wicketpath attribute
class Watir::Element
attribute(String, :wicketpath, 'wicketpath')
end
这将让你使用 'wicketpath' 作为定位:
p browser.li(:wicketpath, 'true').text
#=> "Value 3"
p browser.li(:text, 'Value 3').wicketpath
#=> true
好东西贾斯汀.. –