Mechanize Javascript

I am trying to present a Mechanize form, however, I am not sure how to add the necessary values ​​of the values ​​that some Javascript does. Since Mechanize does not yet support Javascript, and therefore I am trying to add variables manually.

Form Source:

<form name="aspnetForm" method="post" action="list.aspx" language="javascript" onkeypress="javascript:return WebForm_FireDefaultButton(event, '_ctl0_ContentPlaceHolder1_cmdSearch')" id="aspnetForm">

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/..." />

<script type="text/javascript">
<!--
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
</script>

<script language="javascript">
<!--
var _linkpostbackhit = 0;
function _linkedClicked(id, key, str, a, b) {
    if (!b || !_linkpostbackhit) {
        if (!a) {
            __doPostBack(key, id);
            _linkpostbackhit = 1;
        } else {
            if (window.confirm(str)) {
                __doPostBack(key, id);
                _linkpostbackhit = 1;
             }
        }
     }
    return void(0);
}
// -->
</script>

...

<a href="JavaScript:_linkedClicked('123456','_ctl0:ContentPlaceHolder1:Link', '',0,1);">123456</a>

...

</form>

I tried to add two variables:

page.forms.first['__EVENTTARGET']   = '_ctl0:ContentPlaceHolder1:Link'
page.forms.first['__EVENTARUGMENT'] = '123456'

and submit the form:

page.forms.first.click_button(page.forms.first.buttons.first)

The result only returns (repeatedly) the display of the current list of links, as if I had not clicked on any of the links.

Any help would be appreciated. Thank!

+2
source share
3 answers

Using mechanize-1.0.0, do the following:

 agent = Mechanize.new
 page = agent.get('http://127.0.0.1/some.aspx')

 form = page.form("aspnetForm")
 form.add_field!('__EVENTARGUMENT', 'Page$2')
 form.add_field!('__EVENTTARGET', 'ctl00$ContentPlaceHolder1$gvwSomeList')
 page = agent.submit(form) # this gets page 2
+5
source

, Firefox Firebug, , . "", "list.aspx" .

+2
page.forms.first['__EVENTARUGMENT'] = '123456' // -> should be '__EVENTARGUMENT'
+2
source

All Articles