The wireless router of my internet provider sometimes acts up a bit and restarting the device usually works. The problem is that it's in mounted on a wall, behind a furniture in a place that's hard to reach. It's possible to do it remotely by logging in onto the router and pressing the restart button. It's a bother, though, so I thought of writing a short AppleScript to automate the process. I more or less know how to proceed once I'm logged on to the router's interface, but for some reason I can't enter the password and get the interface to click the "log-in " button using Java.
The script I'm using is
tell application "Safari"
set ActiveSearchContent to do JavaScript "document.getElementById('password').value='" & RouterPassword & "'" in O2BoxWindow
delay 2
do JavaScript "document.getElementById('next_button').click()" in O2BoxWindow
delay 2
nd tell
But it doesn't seem to work. I tried entering the commands separately in Safari's Web Inspector and this is what I get:
TypeError: null is not an object (evaluating 'document.getElementById('password').value='xyz'') and TypeError: null is not an object (evaluating 'document.getElementById('next_button').click')
Which is what I don't understand, cos the elements are defined by their IDs.
here's the DOM-Structure of the routers interface:
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>o2.box</title>
<script src="menu_131.js" type="text/javascript"></script><style type="text/css"></style>
<!--<script src="TO2.js" type="text/javascript"></script>-->
<script type="text/javascript">
var isIE = navigator.userAgent.search("MSIE") > -1;
var isOpera = navigator.userAgent.search("Opera") > -1;
var isSafari = navigator.userAgent.search("Safari") > -1;
var setprotectStatus = '1';
function SetCwinHeight() {
/*var iframe = document.getElementById("mainframe");
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = bHeight>dHeight?bHeight:dHeight;
iframe.height = height*/
var iframe = document.getElementById("mainframe");
if(isOpera || isSafari)
{
//iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
}
else if(isIE)
{
iframe.height = iframe.contentWindow.document.body.scrollHeight+8;
}
else//other broswer
{
iframe.height = iframe.contentWindow.document.documentElement.offsetHeight+2;
}
}
function hideBody(hide) {
var status = '';
if ( hide == 1 )
status = 'hidden';
if (document.getElementById) // DOM3 = IE5, NS6
document.getElementById('bodyhide').style.visibility = status;
else {
if (document.layers == false) // IE4
document.all.bodyhide.style.visibility = status;
}
}
function frmLoad()
{
var setprotectStatus = '1';
if( window.self != window.top )
{
hideBody(1);
self.parent.location.href = self.location.href;
/* var parenturl = parent.window.location.href;
var partsparenturl = parenturl.split("/");
parent.window.location.replace(partsparenturl[0] + '/' + partsparenturl[1] + '/' + partsparenturl[2] + '/index_setupWizard.html');
*/ }
else
{
hideBody(0);
}
}
</script>
<link href="menu_131.css" rel="stylesheet" type="text/css">
</head>
<body onload="frmLoad()" class="body_center" id="bodyhide" style="" onresize="javascript:SetCwinHeight();">
<div class="topinfo"></div>
<div class="logo_header">
<span id="headerText"><b>Einrichtungsassistent </b> Kennwort</span>
</div>
<div class="main">
<div class="mainnav">
<div class="menu"></div>
<div id="menu" style="">
<div class="menu_head"></div>
<ul class="flipMenu">
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">Übersicht</a><ul style="display: none;"></ul></li>
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">Internet</a><ul style="display: none;"></ul></li>
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">Telefonie</a><ul style="display: none;"></ul></li>
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">Heimnetz</a><ul style="display: none;"></ul></li>
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">Sicherheit</a><ul style="display: none;"></ul></li>
<li class="flipLock"><a target="mainframe" class="padding20" style="color:#686868">System</a><ul style="display: none;"></ul></li>
</ul>
<div><a class="selected_SetupWizard_Lock">Einrichtungsassistent</a></div>
<br><br>
</div>
</div>
<div class="data">
<iframe id="mainframe" name="mainframe" src="kennwortlock.cmd?action=view" width="100%" onload="javascript:SetCwinHeight();" frameborder="0" height="509"></iframe>
</div>
<div></div>
</div>
</body></html>
Can anyone help, please? Any help would be appreciated.