如何使用 Watir 循环浏览链接并单击每个链接
我有一个带有网格的网页,某些列的列标题中有一个链接,该链接将按该列对值进行排序[通过往返服务器]。
我想编写一个 Watir 测试来识别这些排序链接并连续单击每个链接。这是一个冒烟测试,可确保排序表达式不会导致运行时异常。
我的问题是,(1)识别这些链接,(2)连续单击每个链接的最佳方法是什么?这是我到目前为止所拥有的:
$ie.table(:id, "myGrid").body(:index, 1).each do | row |
row.each do | cell |
## todo: figure out if this contains a sort link
## todo: click the link now, or save a reference for later?
end
end
I have a web page with a grid, and some columns have a link in the column header that will sort the values by that column [by round-tripping to the server].
I want to write a single Watir test that will identify those sorting links and click each one in succession. This is a smoke test that ensures there are no runtime exceptions resulting from the sort expression.
My question is, what is the best way to (1) identify these links, and (2) click each one in succession? This is what I have so far:
$ie.table(:id, "myGrid").body(:index, 1).each do | row |
row.each do | cell |
## todo: figure out if this contains a sort link
## todo: click the link now, or save a reference for later?
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能单击循环内的每个链接,因为单击链接将触发页面加载,并且我相信这会使其他 Watir 链接元素无效。
因此,我建议您获取链接的 ID,然后相互循环进行点击。
例如,我会向这些排序链接添加一个特定的类以及一个有意义的 id。
大致如下:
然后你可以这样选择它们:
然后,你像这样点击:
希望有帮助!
I think it won't be possible to click each link inside the loop since clicking a link will trigger a page load and I believe this invalidates the other Watir Link Elements.
So, what I suggest is that you take the IDs of the links and then loop over each other doing the clicks.
For instance, I would add an specific class to those sorting links and a meaningful id too.
Something along the lines of:
Then you can pick them with this:
And then, you do your clicking like this:
Hope that helps!