Search code examples
mechanize-python

How to select the correct submit button with mechanize for Python?


I'm trying to submit a form (using mechanize in Python) that has two submit buttons as shown below.

<input type="submit" value="Save Changes " name="SaveChanges">
<input type="submit" value="Reboot" name="SaveChanges">

Mechanize "print control" shows this...

<SubmitControl(SaveChanges=Save Changes )>
<SubmitControl(SaveChanges=Reboot)>

How do I select the "Reboot" submit button with mechanize? I've tried:

br.submit()
br.submit("Reboot")
br.submit("SaveChanges=Reboot")

The correct form is selected, but none of these submit options are working. I'm new to Python and would appreciate any help.


Solution

  • I just figured it out.

    br.submit(nr=1) 
    

    will select the second submit button (nr count starts with zero)