CODA CODA - 1 year ago 89
Ruby Question

How to get href with Watir using Ruby

I'm trying to use Watir to grab a specific link on a page:

Screenshot: Here is the href I am trying to grab.

My guess is I need to specify the ancestor element

(?) then traverse down to the
tag and grab its
somehow, but I'm not sure what the syntax of my code would need to be do that.

Any ideas or tips?

pjd pjd
Answer Source

You should be able to get the value of the href with

browser.span(:class, 'biz-website').a.href

If the class 'biz-website' is not unique for spans on your page, you can also use 'biz-website js-add-url-tagging'. If that is still not unique, you could also try

browser.span(:text, 'Business website').parent.a.href

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download