Created
April 20, 2010 03:57
-
-
Save spritle/372010 to your computer and use it in GitHub Desktop.
mechanize with form login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can someone make the last line work?
mechanize_agent.click(page.link_with(:text => /LOGOUT/))