Forms not seen by Mechanize (US Bank login)

P

Phil Henley

I'm writing a script to login to my bank. Here's how the login
procedure works through a web browser:

1. enter and submit your username on the bank home page
2. on a new page: answer a "Shield ID" question (a personalized
question)
3. on a new page: enter your password
4. on a new page: you now have access to your account info

Using Firefox and the Live HTTP Headers add-on, I see that javascript
(or something??) is filling out various forms for me at each step which
takes me to the next page. Only one of these forms is visible to the
user in the browser at each step (login at step 1, and shield id at step
2), javascript seems to be filling out the rest of the forms for the
user.

In my script, I'm using Mechanize to manually fill out and submit all
these forms.

This works fine until I get to Step 3 where you enter your password.
When I view the forms on this page with Mechanize only two forms show
up. The password form (as well as a few others) don't show up.

If I go through the process with FireFox and the add-on mentioned above,
I see that the form holding my password is called PSWD, but if I try to
access that form directly from my script it can not find the form.

Any ideas how I can access this form from my script?

Here's a quick example of the code I'm using:

agent = Mechanize.new
page = agent.get "http://www.usbank.com/en/PersonalHome.cfm"
form = page.form('logon2')

form.requestCmdId = "VALIDATEID"
form.reqcrda = "my_username"
form.reqcrdb = ""
form.doubleclick = "1"
form.NONCE = "NoNonce"

form.MACHINEATTR =
"colorDepth%3D24%7Cwidth%3D2048%7Cheight%3D1152%7CavailWidth%3D2048%7CavailHeight%3D1122%7Cplatform%3DWin32%7CjavaEnabled%3DNo%7CuserAgent%3DMozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+6.1%3B+en-US%3B+rv%3A1.9"

form.bankLogin = "internetBanking"
form.USERID = "my_username"

page = agent.submit form

#Get the Shield ID question
question = page.body.match(%r|<td class=f3 colspan=3
valign="middle">.*?</td>|).to_s.sub('<td class=f3 colspan=3
valign="middle">', '').sub("</td>", "")

result = case question
when "question 1" then "answer1"
when "question 2" then "answer2"
else "failed"
end

if result == "failed"
puts "\nFailed to answer the ID Shield question."
puts question
sleep 3
exit
end

form = page.form('challenge')

# ID Shield answer
form.ANSWER = result
form.CHALLENGEANSWER = result
page = agent.submit form


#We are now on the password page
form = page.form('password')
form.PSWD = "my_password"

- here is where I get an error "undefined method 'PSWD='
 
B

brabuhr

I'm writing a script to login to my bank. Here's how the login
procedure works through a web browser:

1. enter and submit your username on the bank home page
2. on a new page: answer a "Shield ID" question (a personalized
question)
3. on a new page: enter your password
4. on a new page: you now have access to your account info

Using Firefox and the Live HTTP Headers add-on, I see that javascript
(or something??) is filling out various forms for me at each step which
takes me to the next page. Only one of these forms is visible to the
user in the browser at each step (login at step 1, and shield id at step
2), javascript seems to be filling out the rest of the forms for the
user.

In my script, I'm using Mechanize to manually fill out and submit all
these forms.

This works fine until I get to Step 3 where you enter your password.
When I view the forms on this page with Mechanize only two forms show
up. The password form (as well as a few others) don't show up.

* Perhaps there is a way to manipulate the DOM to add the missing form
just like Javascript would? (There appears to be a Mechanize method
to add a field to a form. [1])

* Perhaps there is a way to manually build the POST that would be
generated from the form?

* Try a different library like FireWatir or Celerity?

[1] http://rdoc.info/github/tenderlove/mechanize/master/Mechanize/Form#add_field!-instance_method
 
P

Phil Henley

I tried the mechanize add_field! method and it appears to properly add
the fields and values to the form, but I wasn't able to
successfully login when submitting it. Celerity and FireWatir look
promising though, I'll start tinkering with those tonight. Thanks for
the tips!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top