【发布时间】:2016-05-21 22:06:45
【问题描述】:
我需要从特定页面的所有 span 中读取名为“data-contents”的属性的值
<span tabindex="0" title="" class="text-warning ng-isolate-scope" role="button" data-original-title="" data-toggle="popover" data-placement="top" data-html="true" data-contents="If you are not sure which type of occupation in the list to choose, please call us on (852) 2884 8888 and we'll be happy to help you." data-content="If you are not sure which type of occupation in the list to choose, please call us on (852) 2884 8888 and we'll be happy to help you." data-da-popover="" data-da-popover-id="daPopover1455178167018" data-container="body" data-trigger="focus"><img src="/app/ui/images/question-icon.png"> </span>
我已经写了以下代码,
b.spans.each do |span|
puts span.data-contents
end
但它会抛出此错误':未定义的局部变量或方法`contents' for main:Object (NameError)'
谁能帮我读一下这个数据内容的价值?
【问题讨论】:
-
可能与
attribute-accessor 一样在stackoverflow.com/questions/1443455/… 中? -
是的,太好了,可以了,谢谢。
-
然后让我们关闭为重复
-
是的,谢谢你指导我。
-
对于 html5 有效属性(如 'data-*'),Justin 下面的回答应该优于 attribute_value 方法。
标签: ruby watir watir-webdriver watir-classic