这是 Rspec 功能。
given (:send_selector){ 'button.confirm'}
feature "when talent has not applied." do
given (:apply_button) { find('button[data-selector="offer-apply-button"]') }
before(:each) { visit offer_path(offer.id) }
scenario "Talent applies to offer with default cv", js: true do
apply_button.click
expect(page).to have_selector(send_selector)
find_button(send_selector).click
wait_for_ajax
# other expectations
end
end
它满足了选择器的期望,但随后抛出了错误
Capybara::ElementNotFound:
Unable to find button "button.confirm"
指向带有find_button(send_selector).click的行
我还尝试使用page.find_button(send_selector).click
和 find_button(send_selector).trigger('click')
但第一个仍然抛出错误,第二个似乎什么也没做,因为负责操作的 Controller 从未被调用,并且模态仍然存在我在下一行截图。
我运行了 poltergeist 调试器,并且 html 出现在页面上。
这是 capybara 看到的模式(使用 save_screenshot()
方法)
最佳答案
问题在于 find_button
不采用 CSS 选择器 - http://www.rubydoc.info/gems/capybara/Capybara/Node/Finders#find_button-instance_method - 它采用按钮的名称、id、标题或文本内容(与 click_button
和 'have_button' 相同)。
在您的回答中,sleep 1
与解决问题无关,它已被修复,因为您从find_button
交换到find
,确实需要 CSS 选择器
关于javascript - 为什么Capybara/Rspec在Sweet Alert Modal中找不到按钮,但have_selector返回true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43213587/