我是一名新手爱好者,正在尝试为使用 capybara 2.10.1 和 rspec 的 2017 年 Rails 项目编写我的第一个 rspec。
我启动了,执行了 save_and_open_page,ctrl-shift-c,右键单击一个链接以查找一些深度随机引导导航栏登录链接的 xpath:
scenario "valid with correct credentials", focus: true do
expect(page).to have_link "LOG IN"
find('#myNavbar > ul.nav.navbar-nav.navbar-right.signlogin > li:nth-child(2) > a').click
expect(page).to have_content("Sign in").twice
fill_in "Email", with: @fan.email
fill_in "Password", with: @fan.password
click_button "Sign in"
find('.dropdown-toggle').click
expect(page).to have_link "Logout"
expect(page).to have_current_path root_path
end
但是,假设因为它是水豚 2.10.1,have_content("").twice 给了我
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching xpath "/html"
我可以在页面上找到其他独特的东西,但一直没有成功地尝试通过谷歌解决它(水豚显然是海狸大小的两倍,是世界上最大的啮齿动物)