Link to home
Start Free TrialLog in
Avatar of teltel
teltel

asked on

Calling a Javascript function in Python

Hi All,

I am writing a python script to open up some javascript webpages in a device.  I need to click a button to reset the device.  So I am basically asking: is there a way to "click" a button in Python, or call the javascript onReset() function?  I have tried the ClientForm module but it cannot parse out the button that I want correctly.  Below is the source code of the webpage just for info:

<html><head><link rel=stylesheet href=style.css type=text/css><title>Reset</title></head><body><form name=resetform><table border=0><tr><td class=header><strong>Reset</strong></td></tr><tr><td class=small><strong>Warning! Resetting the system will terminate all network connections and reset your browser connection.</strong></td></tr><tr><td><hr></td></tr><tr><td><input type=radio checked name=RESET value=NORMAL checked> Reset and execute Main Application</td></tr><tr><td><input type=radio name=RESET value=STAGE1> Reset and execute Downloader Application</td></tr><tr><td><hr></td></tr><tr><td><input type=button class=button value=" Reset " onclick=onReset()></td></tr></table></form><script language="JavaScript"><!--

function onReset(){for(i=0;i<document.resetform.RESET.length;i++){if(document.resetform.RESET[i].checked) document.hform.RESET.value=document.resetform.RESET[i].value;}document.hform.submit();setTimeout("Wait()",500);return true;}function Wait(){document.write("<html><body bgcolor=#FFFFFF><center>"+"Please wait while the BVP8762 is rebooted..."+"</body><script language='JavaScript'>"+"function Retry(){window.top.location='index.htm';setTimeout('Retry()',500);}"+"</script></html>");document.close();setTimeout("Retry()",2000);return true;}//--></script><form name=hform method=POST><input type=hidden name=RESET value=NORMAL></form></body></html>

I don't know much javascript and am new to Python.  Thanks for any help!  ^_^
ASKER CERTIFIED SOLUTION
Avatar of mish33
mish33
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of teltel
teltel

ASKER

Thanks mish33, it works perfectly.

Would you mind explaining the last line a bit more please?  I am still a little confused as to how/why it would work.  Many thanks again!
Basicly I translated from Javascript to Python.

HTML code in the start is the first form to allow user select the type of reset.
Then onClick call Javascript which substitutes user selected value from the the first form to the second form and sends it.
So inside urlencode you see data from the second form and urlopen().read() sends it.

Don't hesistate to ask for further detail clarification.
Avatar of teltel

ASKER

Thanks!