Capybara::Ambigously:不明确匹配,找到 2 个与可见 xpath“/html”匹配的元素

问题描述 投票:0回答:0

我正在为 2017 年的项目编写第一个 rspec 测试,该项目使用 capybara、rspec、devise、bootstrap 和rails

scenario "invalid with unregistered account" do
    
    within('#myNavbar') do
      click_link('LOG IN')
    end  

    fill_in "Email", with: Faker::Internet.email
    fill_in "Password", with: "FakePassword123"
    click_button "Sign in"

    expect(page).to have_content("Email or password fail.")
    expect(page).to have_current_path new_fan_session_path
    expect(page).to have_selector(:link_or_button, 'Sign in')
  end

这有效,但前提是我删除布局/应用程序文件顶部的

<!DOCTYPE html>
。否则,
expect(page).to have_content("Email or password fail.")
会给我错误

Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"

...我可以使用

expect(page).to have_css '.alert'
来解决它,这是使用 save_and_open_page 等检查类的引导警报。

否则,我已经彻底检查了整个路径,包括所有渲染等,是否有流氓或双重或这些标签之外的代码等,但没有发现任何问题。

还有其他原因导致此错误发生吗?

rspec devise capybara
© www.soinside.com 2019 - 2024. All rights reserved.