Home > watir > watir to count the links in a search list on a webpage

watir to count the links in a search list on a webpage

October 27th, 2009 Leave a comment Go to comments

Some times I need to check the amount of the links in a search list, at first I try and failed by:
ie.links(:id, /bra bra/).length

and then I find a solution by:
ie.div(:id, “searchList”).links

and then by googles, I find a better solution:
links_searchlist = ie101.links.find_all { |link| link.class_name == ‘permalink’ }
puts “the links in the searchlist:”
puts links_searchlist.length

and in another case, following code also works:
searchlistlinks = ie102.links.find_all { |link| link.id =~ /hitURL/ }
links_searchlist = searchlistlinks.length
puts links_searchlist

following can also work:
searchlistlinks = ie33.links.find_all { |link| link.href =~ /something/ }
but be careful that the following (url) will not work:
searchlistlinks = ie33.links.find_all { |link| link.url =~ /something/ }

Recently I found the best solution by google:
links = ie51.div(:id, ‘threadlist’).html.scan(/something/).count
puts links



Categories: watir Tags: ,
  1. No comments yet.
      
                  
      

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word