capybara - Clicking a button without an id

纵然是瞬间 提交于 2019-12-23 12:23:14

问题


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

<div class="modal-footer"><button class="btn" data-dismiss="modal">Kapat</button></div>

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

click_on "Kapat"

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 ?


回答1:


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


来源:https://stackoverflow.com/questions/14773936/capybara-clicking-a-button-without-an-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!