click on one Specific button using capybara in rails
Solution 1
I think the problem is that all the values return a match because they all contain 'Save'.
Try assigning each one a distinctive id and using that instead.
Solution 2
Matching With Exactness - from the GitHub docs. Using exactness would probably make less of an impact than altering your templates.
click_button('Save', exact: true)
This would only find the exact match and skip the 'Save blah' action.
chirag.sweng
Updated on July 23, 2022Comments
-
chirag.sweng almost 2 years
I am working with rails 3 and currently writing test with capybara using selenium driver, I have issue as below
In one form i have 3 button named "save and add another", "save and continue editing" and "Save" Now, if i try to save form by capybara as below
click_button 'Save'
Then this throws error called 'Save' button with id,title or value not found Now if i remove the above 2 buttons and then i try that then it works
FYI, My 3 button's html as below,
<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">
Please let me know if anyone has an idea.
-
DanS about 12 yearsI think the problem is that the last one only works when the other buttons are removed...
-
chirag.sweng about 12 yearsThanks, but yes i know that 'Save' button should work if i write
click_buttion 'Save'
, but currently it is not working and it throws error as i said in my qustion.. if i remove my above 2 buttons then only thisclick_button 'Save'
works -
chirag.sweng about 12 yearsNo this is also not working.. and it throws error
no button with value or id or text 'Save' found
but anyway, i get the solution, i have added ids to those buttons and then it works fine, thanks for your answers and time -
IAmNaN over 11 yearsTo be clear, an id, text or value is expected. It will not match by name.
-
Gino about 3 yearsPrefer this answer to the accepted answer as it doesn't involve editing your markup.