Skip to content

Instantly share code, notes, and snippets.

@spritle
Created April 20, 2010 03:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spritle/372010 to your computer and use it in GitHub Desktop.
Save spritle/372010 to your computer and use it in GitHub Desktop.
mechanize with form login
require 'mechanize'
mechanize_agent = Mechanize.new
# Visit login page
mechanize_agent.get('http://www.cmsimple.org/demo/?Welcome&login') do |page|
remote_login_form = page.form('login')
remote_login_form.passwd = "test"
# Click submit to login
mechanize_agent.submit(remote_login_form, remote_login_form.buttons.first)
# Access the protected page - Settings
settings_page = mechanize_agent.get('http://www.cmsimple.org/demo/?&settings')
# Get the logged-in main menu.
settings_page.search(".edit").each do |tr|
tr.children.each do |td|
td.children.each do |menu_links|
puts menu_links.children
end
end
end
# mechanize_agent.click(page.link_with(:text => /LOGOUT/))
end
@spritle
Copy link
Author

spritle commented Apr 20, 2010

Can someone make the last line work?
mechanize_agent.click(page.link_with(:text => /LOGOUT/))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment