我有一个可以从Bash和CasperJS运行的脚本,它不断地ping我的服务器。如果所有服务器都关闭,则使用CasperJS脚本重新启动调制解调器。根据经验,当问题发生时,外部机器仍然可以ping我们的调制解调器,但内部机器失去了互联网访问。所有机器都在Ubuntu上运行。
两个脚本在本地运行时工作正常,但在外部服务器上运行时,CasperJS失败并出现以下错误:
CasperError:无法在不存在的选择器上调度mousedown事件:xpath选择器:/ html / body / form / div [2] / div / div [1] / div / div [2] / div / div [2] / div /表/ tbody的/ TR / TD /输入
上述错误与单击按钮以重新启动调制解调器有关。
该脚本定期截取屏幕截图,当从服务器运行时,屏幕截图显示在登录路由器的Web GUI时脚本卡住了。凭据输入正确,但不接受,表示无法识别用户名和密码。调制解调器GUI具有登录形式,而不是身份验证弹出窗口。
当我使用URL和外部IP地址访问页面时会发生这种情况;但同样,只能从服务器,而不是我的本地机器。我不确定这可能是与我的代码或调制解调器的Web GUI有关的问题。
我的CasperJS代码如下,出于安全原因进行了编辑。
var casper = require('casper').create()
var x =require('casper').selectXPath;
casper.start('http://router-webpage.com/);
casper.thenClick(x('/html/body/div[2]/div/div[1]/div/div/div/div/div/form/div[1]/input'), function() {
this.sendKeys('#username', 'USERNAME');
this.sendKeys('#password', 'PASSWORD');
casper.capture('creds.png');
});
casper.thenClick(x('/html/body/div[2]/div/div[1]/div/div/div/div/div/form/div[3]/a'), function() {
});
casper.wait(5000, function() {
casper.capture('logged.png');
});
casper.thenOpen('http://router-webpage.com/settings/restart/', function() {
});
casper.wait(5000, function() {
casper.capture('rebootpage.png');
});
casper.thenClick(x('/html/body/form/div[2]/div/div[1]/div/div[2]/div/div[2]/div/table/tbody/tr/td/input'), function() {
console.log('Clicked reboot');
});
casper.wait(10000, function() {
casper.capture('rebootconf.png');
console.log('Confirmation popup loaded');
});
casper.thenClick(x('/html/body/div[1]/div[2]/div/div[2]/a[1]'), function() {
console.log('Reboot submitted');
});
casper.run();
答案 0 :(得分:0)
问题已经解决。
从内部地址连接允许通过域名或IP地址进行即时访问,但在外部,必须明确说明端口才能提供访问权限。
脚本现在可以从服务器正常运行。