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
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"]