【发布时间】:2020-08-05 21:46:59
【问题描述】:
我需要通过js在网页中提交表单来自动化我的工作,我做了这样的代码:
var ie = new ActiveXObject("InternetExplorer.Application");
ie.visible = true;
ie.navigate("http://www.google.com");
while (ie.busy) WScript.Sleep(100);
ie.document.getElementsByName('q')[0].value ="3";
var Butn = ie.document.getElementsByName('btnK')[0];
Butn.click();
但我希望这段代码可以与另一个网络浏览器(例如 Firefox)一起使用,所以我尝试了这样的方法:
var ie = new ActiveXObject("Shell.Application");
var commandtoRun ="C:\\Program Files\\Mozilla Firefox\\firefox.exe";
ie.ShellExecute(commandtoRun,"http://www.google.com", "1");
while (ie.busy) WScript.Sleep(100);
ie.document.getElementsByName('q')[0].value ="3";
var Butn = ie.document.getElementsByName('btnK')[0];
Butn.click();
但是这段代码会报错:
'ie.document' 为 null 或不是对象
800A13F
我要求以下两种方法中的任何一种:
*处理已经打开的网络浏览器,不仅打开一个然后应用代码。
*以正确的方式识别打开的网络浏览器以应用代码。
【问题讨论】:
标签: javascript internet-explorer firefox browser