I am using mechanize to deal with a form . I have parsed the form using mechanize and the output comes is as follows:
{forms
#<Mechanize::Form
{name nil}
{method "POST"}
{action "/dashboard/checks/50114dbeae6f61b428000ad8"}
{fields
[hidden:0x60c476a type: hidden name: _method value: put]
[text:0x60c4616 type: text name: check[name] value: Testing]
[text:0x60c4512 type: text name: check[url] value: http://www.pintile.com]
[text:0x60c445e type: text name: check[interval] value: 120]
[text:0x60c435a type: text name: check[maxTime] value: 1500]
[textarea:0x60c4116 type: name: check[tags] value: ]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons
[button:0x60c3d88 type: submit name: value: ]
[button:0x60c3d24 type: submit name: delete value: ]
There are 2 buttons in this form
Save Changes(1st), Delete(2nd),
I use the following code to save the changes and it works fine:
form.field_with(:name => "check[name]").value = "Testing"
button = form.buttons.first
agent.submit(form, button)
The changes are saved successfully. But when i try to delete using the code below it does not work:
button = form.buttons.first
agent.submit(form, button)
It does nothing. Please help me out to get over with this issue.
If the website is a typical rails form, the delete button is most likely a JavaScript action. Mechanize does not support JavaScript. You may want to use something like capybara with the web kit driver instead, which has full JavaScript support and all of the functionality you already have in mechanize.