Skip to content

Multi-page login, can't find the form of the second page.  #55

Open
@ronin1770

Description

@ronin1770

Mechanize Browser object is unable to find form on the second page of the login process. Internal data structure of the browser object seems to hold information about the original form.

Here are the chain of events in the multi-stage login process:

  1. User submits his username / password on the first page (let's call it P1)
  2. This information is validated by the website and user is redirected to the second page (let's call it P2)
  3. On P2 user is required to submit answer to the security question.
  4. However, when user tries to find the form / control for the security answer, Mechanize complains the form /control is not found.
  5. If response.text is printed for P2 - it displays the HTML of the P2 correctly

Sample code is shown below:

browser = mechanize.Browser(history=None)

browser.open(LOGIN_URL)
browser.select_form(nr = 0)
browser.form['username'] = UID
browser.form['userpass'] = PWD
resp = browser.submit()

security_url =  resp.geturl()

print( "The security url is: " + str(security_url) )

resp1 = browser.follow_link(security_url)
forms =  list(browser.forms())

for i in range(len(forms)):
    print( forms[i].name )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions