如何使用 Ruby 获取 Watir 的 href

How to get href with Watir using Ruby

我正在尝试使用 Watir 抓取页面上的特定 link:

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

我的猜测是我需要指定祖先元素 biz-website(?) 然后向下遍历到 a 标签并以某种方式获取它的 href,但我不确定我的代码的语法需要这样做。

有什么想法或提示吗?

您应该能够使用

获得href的值

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

如果 class 'biz-website' 对于页面上的 span 不是唯一的,您也可以使用 'biz-website js-add-url-tagging'。如果仍然不是唯一的,您也可以尝试

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