Ruby on rails 在rails中使用mechanize删除类的实例
我正在使用mechanize处理表单。我已经使用mechanize解析了表单,输出如下:Ruby on rails 在rails中使用mechanize删除类的实例,ruby-on-rails,mechanize,Ruby On Rails,Mechanize,我正在使用mechanize处理表单。我已经使用mechanize解析了表单,输出如下: {forms #<Mechanize::Form {name nil} {method "POST"} {action "/dashboard/checks/50114dbeae6f61b428000ad8"} {fields [hidden:0x60c476a type: hidden name: _method value: put] [text:0x60c4616 type:
{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: ]
更改已成功保存。但当我尝试使用下面的代码删除时,它不起作用:
button = form.buttons.first
agent.submit(form, button)
它什么也不做。请帮我解决这个问题 如果网站是典型的rails表单,则删除按钮很可能是JavaScript操作。Mechanize不支持JavaScript。您可能希望在web kit驱动程序中使用类似于capybara的东西,该驱动程序具有完整的JavaScript支持和mechanize中已有的所有功能。下面的代码片段与链接配合得很好。您尝试过单击吗
agent.get("http://your url")
agent.page.link_with(:text => "link name").click
试试看。。
否则如上所述,您可以使用水豚删除是最后一个按钮。因此,您需要:
button = form.buttons.last
agent.submit(form, button)
或者更简单地说:
form.submit form.buttons.last
如果Mechanize对您来说足够好,并且您不需要任何会带来Capybara的javascript支持,那么您应该能够模拟javascript的功能。在这种情况下,需要源代码来更好地了解追加的内容,但我想在提交之前,隐藏字段
\u方法
的值将被删除
替换。嘿,Tanzeeb,非常感谢您的回复。您是正确的删除按钮是一个javascript操作。现在我想触发javascript函数。我找过了,但这是测试用的。请给我更多的建议。这里有一个很好的例子让你开始:问题是它不是一个链接,所以点击不起作用。它由javascript函数触发。
form.submit form.buttons.last