单击Ruby Mechanize按钮
我有一个特别困难的forms,我试图点击搜索按钮,似乎无法做到这一点。 以下是页面源代码的表单代码:
我正在尝试执行标准的机械化点击操作:
login_page = agent.click(homepage.link_with(:text => "Search"))
这是因为按钮使用javascript吗? 如果是的话,有什么建议?
它不是一个链接,它是一个按钮。 您需要做的是查找表单(例如,使用form_with
),然后查找ImageButton并submit
它。
我也很挣扎,特别是因为我的表格有多个按钮。
有多种方式可以提交表单(许多人使用’form_with’块),但这有助于我:
# get the form form = agent.page.form_with(:name => "my-form") # get the button you want from the form button = form.button_with(:value => "Search") # submit the form using that button agent.submit(form, button)
在这里查看更多信息
此外,请确保升级到最新的机械化。 我使用的是mechanize 1.x,它为我上面的代码提供了“未定义的方法”错误。