我正在使用機械化來處理表單。我已經解析使用機械化的形式和輸出來如下:在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