我正在使用rails 3并且目前使用selenium驱动程序与capybara一起编写测试, 我有以下问题
在一种形式中我有3个按钮,名为“保存并添加另一个”,“保存并继续编辑”和“保存” 现在,如果我试图通过下面的水豚保存表格
click_button 'Save'
然后抛出名为“保存”按钮的错误,其中找不到ID,标题或值 现在,如果我删除上面的2个按钮然后我尝试它然后它工作
仅供参考,我的3按钮的html如下,
<input class="btn" type="submit" value="Save and add another" name="_addanother" data-disable-with="Save and add another">
<input class="btn" type="submit" value="Save and continue editing" name="_continue" data-disable-with="Save and continue editing">
<input class="btn" type="submit" value="Save" name="_save" data-disable-with="Save">
如果有人有想法,请告诉我。
答案 0 :(得分:9)
我认为问题是所有值都返回匹配,因为它们都包含“保存”。
尝试为每个人分配一个独特的ID,然后使用它。
答案 1 :(得分:1)
Matching With Exactness - 来自GitHub文档。使用精确度可能比改变模板产生的影响小。
click_button('Save', exact: true)
这只能找到完全匹配并跳过“保存等待”。动作。
答案 2 :(得分:0)
click_button方法需要按钮的id,name,value.Below将起作用。
click_button 'Save and add another'
click_button 'Save and continue editing'
最后一个按钮没有任何错误,因为它的值是'Save'
click_button 'Save'
答案 3 :(得分:-1)
我提出了以下解决方案
模块ValidUserRequestHelper
# for use in request specs
def sign_in_as_a_valid_user
before(:each) do
user = FactoryGirl.create :user
visit user_session_path
fill_in 'user_email', :with => 'name@email.com'
fill_in 'user_password', :with => 'foobar'
click_button 'Einloggen'
end
end