To get the href you can use link.attribute_value(:href)

To match against https://mysite.com you could use a regular expression:

b.links[0].attribute_value(:href) =~ %r{https://mysite.com.*}

which will return a number specifying the match position within the string 
(if there's a match) or nil (if there's no match.)



On Monday, June 29, 2015 at 10:40:30 AM UTC-7, Sergiu Cornea wrote:
>
> Good afternoon guys,
>
> I was wondering if someone could help me. 
>
> Please correct me if I am wrong as I have just started learning Watir and 
> Ruby.
>
> Lets say I have 20 websites to be checked but I don't know the links so 
> what I am doing it is searching for them using the index value as follows:
>
> require 'watir-webdriver'
>
> b = Watir::Browser.new
> b.goto "mysite.com"
>
> b.links.each_with_index do |_, i|
>
> b.link(index: i).click
> end
>
> This piece of code will go and click on all the links that are available 
> on the Home page, however, I want it to just click on the internal links 
> only and not the external ones as well, for example "mysite.com/hello, 
> mysite.com/howareyou.
>
> I have found a work around which is that knowing what index the external 
> websites are you could skip them, however, I believe there must be a way of 
> skipping them by href or so, but because I am new I don't really know.
>
> Thank you in advance.
>
> Regards,
> Cip
>
> This message and its attachments are private and confidential. If you have 
> received this message in error, please notify the sender and remove it and 
> its attachments from your system.
>
> The University of Westminster is a charity and a company 
> limited by guarantee. Registration number: 977818 England. 
> Registered Office: 309 Regent Street, London W1B 2UW.
>

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to