Last active
December 18, 2015 13:19
-
-
Save kevinthompson/5788979 to your computer and use it in GitHub Desktop.
Submit an ASP.net form by clicking a WebForm link using Mechanize.
This file contains hidden or 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' | |
# Fetch the home page | |
browser = Mechanize.new | |
home_page = browser.get('https://www.example-aspnet-site.com/') | |
# Fill out the login form | |
login_form = home_page.forms.first | |
login_form.field_with(:name => /UserName/i).value = ARGV[0] | |
login_form.field_with(:name => /Password/i).value = ARGV[1] | |
user_dashboard = home_page.link_with(:text => /Login/).click |
This file contains hidden or 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
class Mechanize::Page::Link | |
def click | |
if self.href =~ /WebForm/ && form = self.page.form_with(:name => /aspnetForm/) | |
form['__EVENTTARGET'], form['__EVENTARGUMENT'] = self.attributes['href'].scan(/["']([^"']*)["']/).flatten | |
form.submit | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment