watir print/put all visible links

匆匆过客 提交于 2019-12-06 09:46:54

You can also write it by using shorter syntax like this:

puts $browser.links.find_all(&:present?).map(&:class_name)

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?}

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?}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!