bcar
bcar

Reputation: 815

Return a map of all hidden hrefs on a page in watir

Is it possible to return a map of hidden links using watir? I have been trying to find some useful documentation, but have been most unsuccessful.

I need it to be generic enough to return any link thats hidden on page regardless of class, id, etc

style=display: none;

This currently returns me all visible links

full_list = @driver.links.map{|a| a.href}

i'd like to do something like (my syntax is probably way off):

hidden_list = @driver.hiddens.map{:style, a => 'display: none;'} 

Please, please let me know if there is a way!

Thanks!

Upvotes: 0

Views: 193

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

You could find all the links that are not visible? and collect their href attributes:

For example, given the following html:

<a href="somewhere/visible">asdf</a>
<a style="display:none;" href="somewhere/invisible">asdf</a>
<a style="display:none;" href="somewhere/invisible2">asdf</a>

You can do:

hidden_list = @driver.links.find_all{ |a| !a.visible? }.collect(&:href)
#=> ["somewhere/invisible", "somewhere/invisible2"]

Upvotes: 2

Related Questions