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>Warnin g! Resetting the system will terminate all network connections and reset your browser connection.</strong></td>< /tr><tr><t d><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></t d></tr><tr ><td><inpu t type=button class=button value=" Reset " onclick=onReset()></td></t r></table> </form><sc ript language="JavaScript"><!--
function onReset(){for(i=0;i<docume nt.resetfo rm.RESET.l ength;i++) {if(docume nt.resetfo rm.RESET[i ].checked) document.hform.RESET.value =document. resetform. RESET[i].v alue;}docu ment.hform .submit(); setTimeout ("Wait()", 500);retur n true;}function Wait(){document.write("<ht ml><body bgcolor=#FFFFFF><center>"+ "Please wait while the BVP8762 is rebooted..."+"</body><scri pt language='JavaScript'>"+"f unction Retry(){window.top.locatio n='index.h tm';setTim eout('Retr y()',500); }"+"</scri pt></html> ");documen t.close(); setTimeout ("Retry()" ,2000);ret urn 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! ^_^
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
function onReset(){for(i=0;i<docume
I don't know much javascript and am new to Python. Thanks for any help! ^_^
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Thanks!
ASKER
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!