水豚 - 点击一个按钮,没有ID [英] capybara - Clicking a button without an id

查看:173
本文介绍了水豚 - 点击一个按钮,没有ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图点击该HTML code按钮

I'm trying to to click the button in this html code

< D​​IV CLASS =模式躯><按钮类=BTN数据解雇=模式> Kapat< /按钮>< / DIV>

我已经尝试了各种组合的发现,我才成功最接近的是这个code:

I've already tried find with various combinations, the closest I came to success was with this code:

click_on "Kapat"

问题是,有在页面相同的按钮3份,所以我的问题是;有没有指定这个特殊股利的方式?

The problem is that there are 3 copies of the same button in the page, so my question is; is there a way to specify this particular div ?

推荐答案

如果按钮有一个特定的路径,你可以在使用 找到到这条道路,但该元素的路径必须是在页面唯一的,或者你结束了同样的问题(虽然,我相信使用:XPath的会给你在这里多一点灵活性)。

If the button has a specific path, you could use within or a find down to that path, but that path to the element would have to be unique in the page or you end up with the same problem (though, I believe using :xpath would give you a bit more flexibility here).

within ".modal-footer" do
  click_on "Kapat"
end

within ".another-selector" do
  click_on "Kapat"
end

这篇关于水豚 - 点击一个按钮,没有ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆