views:

125

answers:

2
for control in form.controls:

        if control.type == 'text':
            if 'user' in control.name:
                control.value = 'blah'
            if 'mail' in control.name:
                control.value = 'blah'

        if control.type == 'password':
            if 'pass' in control.name:
                control.value = 'blah'

        if control.type == 'checkbox':
            if 'agree' in control.name:
                control.selected = True

        if control.type == 'submit':
            if 'Submit' in control.name:
                control.readonly = False

I fill the form out this way. Then I go to selected the "Agree" checkbox, after doing that I try to use br.submit() to submit the form and send the data. The error I get it:

AttributeError: SubmitControl instance has no attribute 'click'

This is the HTML source of the submit and agree controls:

<input type="submit" name="regSubmit" value="Register" />
<label for="regagree"><input type="checkbox" name="regagree" onclick="checkAgree();" id="regagree" class="check" /> <b>I Agree</b></label>

The HTML source of this particular website has this JavaScript:

function verifyAgree()
{
    if (document.forms.creator.passwrd1.value != document.forms.creator.passwrd2.value)
    {
        alert("The two passwords you entered are not the same!");
        return false;
    }

    if (!document.forms.creator.regagree.checked)
    {
        alert("Please read and accept the agreement before registering.");
        return false;
    }

    return true;
}
function checkAgree()
{
    document.forms.creator.regSubmit.disabled = isEmptyText(document.forms.creator.user) || isEmptyText(document.forms.creator.email) || isEmptyText(document.forms.creator.passwrd1) || !document.forms.creator.regagree.checked;
    setTimeout("checkAgree();", 1000);
}
setTimeout("checkAgree();", 1000);

When I type print forms into IDLE, the form is returned as filled and all the proper controls are selected. I can't for the life of me figure out WHY this isn't working. I've been at it for two days.

Help is greatly appreciated.

A: 

Why not just submit the form as it is shown in the documentation sample:

br.select_form(name="whatever")
response = br.submit()

Clicking on the submit button is just one way to submit the form; using JavaScript is another. So you don't need to go through the trouble of finding the submit control.

loevborg
unfortunately this didn't work either. here is the website im attempting to use my script to make an account and register to http://www.energysuspension.com/forum/index.php?action=registeryou can view the javascript and such, i dont understand why it wont work.after submitting, it just sends me back to http://www.energysuspension.com/forum/index.php?action=register (the same page) and the forms are all empty.
gurk
I don't think there's a legitimate reason for automating registration at a forum.
loevborg
Downvoting accordingly.
loevborg
A: 

We found that Mechanize has often problems with some Javascript on certain pages. That is no surprise, as it is not a real web browser => Did you try it with a tool that is based on a real browser? (e. g. WatiN or iMacros for IE/Firefox/Chrome)?

Ruby8848
yeah, i infact have tried it. i was able to register an account by hand on this particular website. yet my python program was not able to register on this website.here is the website i am attempting to register on using mechanize. i still am unable to get my little script to create an account. its quite frustrating as i don't understand the reason it isn't working. i invite you to attempt to register. http://www.energysuspension.com/forum/index.php?action=registeryou can view the javascript acting on the page through the source (as im sure you know)thank you for your time
gurk