Ruby capybara无法找到链接或按钮"搜索"

时间:2016-06-01 18:11:02

标签: ruby capybara

我遇到了一个简单的脚本问题:

Given(/^I am on the main home page$/) do
  visit 'xxx.se'
end
When(/^I search for "(.*?)"$/) do
|search_term|
  fill_in 'q', :with => search_term
  click_on 'search'
end
Then(/^videos of large rodents are returned$/) do

  expect(page).to have_content 'Samsung'

但我收到了错误

Capybara::ElementNotFound: Unable to find link or button "search"
./features/step_definitions/steps.rb:7:in `/^I search for "(.*?)"$/'

链接到这里检查元素: http://imgur.com/GLbbg7e

2 个答案:

答案 0 :(得分:0)

尝试find("button[aria-label='Search']")它可能会有所帮助 你可以在这里阅读点击 http://www.rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions

答案 1 :(得分:0)

由于click on不支持css选择器,您可以使用find代替

find(:css, "button.search-form-button").click