Selenium 水豚;未找到css定位器
我是黄瓜和水豚的新手,我对以下错误感到困惑:Selenium 水豚;未找到css定位器,selenium,cucumber,capybara,Selenium,Cucumber,Capybara,我是黄瓜和水豚的新手,我对以下错误感到困惑: When I click the "Search" button # features/step_definitions/web_steps.rb:9 Unable to find button #<Capybara::Element tag="button"> (Capybara::ElementNotFound) ./features/step_definitions/web_steps.rb:11:in `/^I
When I click the "Search" button # features/step_definitions/web_steps.rb:9
Unable to find button #<Capybara::Element tag="button"> (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:11:in `/^I click the "([^"]*)" button$/'
features/search.feature:9:in `When I click the "Search" button'
我的步骤如下所示:
When /^I click the "([^"]*)" button$/ do |button_text|
button_text = find('#gbqfb')
click_button button_text
end
我尝试了“单击(按钮文本)和单击链接”方法。我想这可能是我没有看到的明显的东西。我试图找到按钮元素的css定位器,然后单击该元素。我认为不需要更改正则表达式,因为我正在更改“button\u text”局部变量。或者我可以吗?您可以先使用
和查找方法,然后像这样设置单击
first('.page a', :text => '2').click
find('.page a', :text => '2').click
为了你的黄瓜
When /^I click the "([^"]*)" button$/ do |button_text|
first('.page a', :text => "#{button_text}").click
end
或
When /^I click the "([^"]*)" button$/ do |button_text|
find('.page a', :text => "#{button_text}").click
end
When /^I click the "([^"]*)" button$/ do |button_text|
find('.page a', :text => "#{button_text}").click
end