最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer - When using wscript (COM automation) to control IE, why can't I click() a button, yet it works in the

programmeradmin1浏览0评论

I have a flaky wifi access point that I'd like to automate to reboot every night.

It has a typical web interface for administration, and I want to use cscript / wscript to automate IE 11 to reboot the access point.

I'm aware that IE is discontinued, and webdriver / selenium are better. But I'd just like to stick to the built-in windows tools (ergo, internet explorer).

The problem: for some reason, my script can locate and fill in the password field successfully, but there's no response when I click() on the login button. The (JS) script looks like so:

var ie = WScript.CreateObject("InternetExplorer.Application", "ieEvent_");
ie.visible = true;
ie.navigate("/");

function ieEvent_DocumentComplete(pDisp, URL) {
    WScript.echo(URL);
    if (URL.substring(0, 10) !== "http://192")  return;
    var txt_pass = ie.document.getElementById("admin_Password");
    var btn_login = ie.document.getElementById("logIn_btn");
    if ((txt_pass !== null) && (btn_login !== null)) {  // #1: login page
        WScript.echo("#1 login page");
        txt_pass.value = "password";
        btn_login.click();  // doesn't work?
    } else {
        ...
    }
}    

Yet, the exact same code works in the IE dev console:

btn_login = document.getElementById("logIn_btn");
btn_login.click();

Is there any reason click() might be blocked when executed via COM, but not in the dev console?

For the record, the device is a D-Link M15. For those familiar with the device, I know it has a built-in scheduled reboot function. Unfortunately, that functionality is disabled when the device is set to "Extender Mode".

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论