Edited at

Mechanizeでログインする

More than 1 year has passed since last update.


agent#getの引数で、form_withの引数にname属性を設定する

require "mechanize"

agent = Mechanize.new
agent.get("https://www.hoge.com/admin/login") do |page|

login_result = page.form_with(name:"loginform") do |login|
login.field_with(name: "user[email]").value = user
login.field_with(name: "user[password]").value = pass
end.submit
end


参考

http://utage.headwaters.co.jp/blog/?p=1468