我正在使用机械化来处理表单。我已经解析使用机械化的形式和输出来如下:在rails中使用机械化删除类的实例
{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: ]
有这种形式 保存更改(1日),删除(2日)2个按键, 我用以下代码保存更改并且工作正常:
form.field_with(:name => "check[name]").value = "Testing"
button = form.buttons.first
agent.submit(form, button)
更改已成功保存。但是,当我尝试删除使用下面的代码它不起作用:
button = form.buttons.first
agent.submit(form, button)
它什么都不做。请帮我解决这个问题。
嘿Tanzeeb,我非常感谢你的回应。你是正确的**删除**按钮是一个JavaScript操作。现在我想触发这个JavaScript函数。我寻找[链接](https://github.com/thoughtbot/capybara-webkit),但这是为了测试。建议我多点。 – 2012-07-27 09:50:05
下面是一个很好的例子,让你开始:http://www.chadcf.com/blog/using-capybara-javascript-capable-replacement-mechanize – 2012-07-27 15:58:49