如何使用 watir 从跨度中读取 "data-contents"- 属性的值?

How to read values of "data-contents"-attributes from spans with watir?

我需要从特定页面的所有跨度中读取名为 "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

但是它抛出这个错误':main:Object (NameError)'

的未定义局部变量或方法`内容'

任何人都可以帮我阅读这个数据内容的价值吗?

您可以像获取其他属性一样获取数据以及 aria 属性。唯一的区别是方法名称使用下划线而不是破折号。

要获取数据内容属性,您可以这样做:

puts span.data_contents