CODA CODA - 1 month ago 27
Ruby Question

How to Get href with Watir (Ruby)

What I'm trying to do: Use Watir to grab a specific link on a page

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

The struggle: My guess is I need to specify the ancestor element

biz-website
? then traverse down to the
a
tag and grab it's
href
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

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

Comments