Reputation: 287
$browser.links.each do |link|
puts link.attribute_value("class")
end
How do I get all the visible/existing links in the put statement?
Upvotes: 2
Views: 1993
Reputation: 253
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?}
Upvotes: 0
Reputation: 1905
You can also write it by using shorter syntax like this:
puts $browser.links.find_all(&:present?).map(&:class_name)
Upvotes: 3
Reputation: 57262
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?}
Upvotes: 2