问题
$browser.links.each do |link|
puts link.attribute_value("class")
end
How do I get all the visible/existing links in the put statement?
回答1:
You can also write it by using shorter syntax like this:
puts $browser.links.find_all(&:present?).map(&:class_name)
回答2:
This will output value of class
attribute for all existing links on the page:
$browser.links.each {|link| puts link.attribute_value("class")}
This will output value of class
attribute for all visible links on the page:
$browser.links.each {|link| puts link.attribute_value("class") if link.visible?}
回答3:
If you require the class name of the links, you can use
$browser.links.each {|link| puts link.class_name if link.visible?}
or if you require any specific attribute of the link, you can use
$browser.links.each {|link| puts link.attribute_value("attribute_name") if link.visible?}
来源:https://stackoverflow.com/questions/12590633/watir-print-put-all-visible-links