views:

28

answers:

0

I am struggling with this. I have a fully tested python script. I have to make a small change wherein I have to first click on a radio button which in turn automatically executes a javascript function forwarding the page to a search form.

My working platform : Linux

Language : Python

Radio button code :

<input type="radio" language="javascript" onclick="javascript:setTimeout('__doPostBack(\'_ctl0$Main$SearchRadio\',\'\')', 0)" value="SearchRadio" name="_ctl0:Main:SearchRadio" id="_ctl0_Main_SearchRadio">

Javascript code on the page :

<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>

This is what selenium does. Not sure if it helps at all.

 def test_untitled(self):
        sel = self.selenium
        sel.open("/Search/results.aspx")
        sel.click("_ctl0_Main_SearchRadio")
        sel.wait_for_page_to_load("30000")
        sel.type("-InputTextField", "ThinkCode")
        sel.click("_SearchMainUser")
        sel.wait_for_page_to_load("30000")
        try: self.failUnless(sel.is_text_present("ThinkCode"))
        except AssertionError, e: self.verificationErrors.append(str(e))

All I am trying to do is go to the resulting page that we are redirected to once we click the radio button. I read about javascript horrors in python web-scraping using urllib2. Hope a kind pythonista will help me soon :)