使用 Watir-Webdriver,我想将焦点更改为 iframe 并获取其中的链接。
这是html代码
<iframe id="top_right" src="otherwebsite.com/need content src">
<a href="need this"> <img src="need this" /> </a>
所以我想要的是进入iframe
,获取它的src,捕获href
和src
img
元素,最后单击这些元素来检索数据。
这是我使用 Ruby 的尝试:
require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'somesite.com'
b.wait
f = b.frame(:id => 'top_right').link(:index => 1).click
我已经到这里了,但不幸的是我仍然收到以下回复:
in `assert_exists': unable to locate element, using {:index=>1, :tag_name=>"a"} (Watir::Exception::UnknownObjectException)
所以如果有人能提供一些帮助,那就太好了。
最佳答案
您正在尝试单击框架中的第二个链接 (:index=>1
)。看起来框架没有两个链接。尝试单击第一个链接 (:index=>0
):
b.frame(:id => 'top_right').link(:index => 0).click
关于ruby - watir webdriver 进入 iframe 并获取元素的 src,然后单击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455269/