Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click on one Specific button using capybara in rails

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.

like image 334
chirag.sweng Avatar asked Apr 09 '12 09:04

chirag.sweng


People also ask

How do you click a button on capybara?

Method: Capybara::Node::Actions#click_button Finds a button on the page and clicks it. This can be any <input> element of type submit, reset, image, button or it can be a <button> element. All buttons can be found by their id, name, test_id attribute, value, or title.

What is Capybara in rails?

What is Capybara? Capybara is an acceptance test framework for web applications. It's a common choice for end-to-end, acceptance, or integration testing in Rails applications. It allows developers to simulate a user on a web page and make assertions based on the content and environment of the page.


1 Answers

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.

like image 107
DanS Avatar answered Sep 24 '22 17:09

DanS