John,
        I've done this in the past by grabbing all the links of a
certain type and storing them to an array.  Then, with your random
number variable (let's call it "n"), you can just do ArrayName(n) to
grab one.  For instance:

##      For each link $ie finds, do the following:  Take my Array, and
add the href address of each link if and only if the address looks like
"http://www.google.com";.


                hrefs = Array.new
                url = "http://www.google.com";

                ie.links.each do |link|
                        hrefs << link.href if /(#{url})/ =~ link.href
                end


##      Then, using .length, you can grab the length of your Array and
use it as your random number endpoint.


                length = hrefs.length  #grab the length
                random = rand(length)  #set a random number up to that
link
                
                newlink = href[random] #set the link choice to the
variable newlink

                ie.goto newlink      #go to it!


The above code can be simplified into two lines or so, but I wanted you
to be able to see what I was doing.

Hope that helps!

Thanks,

Adam Reed
QA Engineer
CORT Business Services

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of John
Sent: Tuesday, March 13, 2007 8:29 AM
To: [email protected]
Subject: [Wtr-general] count specific links

Hi,

I want to count all links in the page which have "catalog/tree" in their
url and then click one randomly. I know how to generate a random number,
but how can I count the number of links?

Thanks!
John
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6867&messageID=19777#19777
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to