Array Example for test Automation

2019-02-21 08:09发布

Array Example for test Automation

Please can i get some help for ruby array to get all text ............. Please find the attachment

# For example:

  ary = @browser.p(class:"sv ng-binding ng-scope")
  ary = Array.new
  p ary.length
  ary.each do |myRole|
    puts "User role: #{myRole.text}"
  end

# but its not working

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-21 09:01

The p method returns the first matching p element. To create a collection, you need to pluralize the method name - ie ps. ps will return an enumerable object (ie like an Array), where each element is a Watir element.

ary = @browser.ps(class:"sv ng-binding ng-scope")
p ary.length
ary.each do |myRole|
  puts "User role: #{myRole.text}"
end

If you are trying to collect the text from each element, it can simply be:

roles = @browser.ps(class:"sv ng-binding ng-scope").map(&:text)
#=> ["NASS InfoPass Scheduler", "NASS Adjudications Scheduler"]
查看更多
登录 后发表回答