浏览器 url 不返回新 url
我正在尝试使用 rspec 和 watir 来做一些 tdd 并遇到了一个我似乎无法解决的问题。我想让 watir 单击链接 (target="_blank"),然后获取新加载页面的 url。 Watir 单击该链接,但当我尝试获取 url 时,我收到的是旧 url,而不是当前的 url。 Watir 文档似乎表明浏览器 url 方法将返回当前 url。我发现一篇博客文章似乎通过让 Watir 执行一些 javascript 来获取当前 url 来解决这个问题,但这对我来说不起作用。有没有办法通过 Watir 的链接点击来获取当前的 url?
<!-- the html -->
<a href="http://www.linkedin.com" target="_blank">LinkedIn</a>
#The rspec code
it "should load LinkedIn" do
browser.link(:href => "http://www.linkedin.com").click
browser.url.should == "http://www.linkedin.com"
end
I am experimenting with using rspec and watir to do some tdd and have come across a problem I can't seem to get past. I want to have watir click a link (target="_blank") and then get the url of the newly loaded page. Watir clicks the link but when I attempt to get the url I receive the old url not the current. Watir docs seem to indicate that the Browser url method will return the current url. I found a blog post that seems to solve this issue by having Watir execute some javascript to get the current url but this isn't working for me. Is there anyway to get the current url from a link click with Watir?
<!-- the html -->
<a href="http://www.linkedin.com" target="_blank">LinkedIn</a>
#The rspec code
it "should load LinkedIn" do
browser.link(:href => "http://www.linkedin.com").click
browser.url.should == "http://www.linkedin.com"
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目标将在新的浏览器窗口中加载链接,因此您需要切换到该窗口以断言 url:
请参阅:http://watirwebdriver.com/browser-popups/ 了解更多示例
The target will load the link in a new browser window, therefore you need to switch to that window to assert the url:
See: http://watirwebdriver.com/browser-popups/ for more examples