Javascript 使用ShellExecute正确识别opend Webbrowser以使用document.getElement

Javascript 使用ShellExecute正确识别opend Webbrowser以使用document.getElement,javascript,internet-explorer,firefox,browser,Javascript,Internet Explorer,Firefox,Browser,我需要通过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].

我需要通过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();
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();
但我想让这段代码与另一个web浏览器(如Firefox)配合使用,所以我尝试了以下方法:

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();
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'为空或不是对象

800A13F

我要求以下两种方式中的任何一种:

*处理一个已经打开的web浏览器,不仅仅是打开一个然后应用代码


*以正确的方式识别打开的web浏览器以应用代码。

我可以看到您使用的ActiveX对象仅受IE浏览器支持

此对象是Microsoft扩展,仅在Internet Explorer中受支持

如果你想自动化其他浏览器,比如Firefox,我建议你试试看。我认为它更适合满足你们的要求

它可以使用许多开发语言来自动化浏览器

看起来还可以获取已打开浏览器的对象


请参见此处:

Thank you@Deepak MSFT,代码的第一部分工作得非常完美它打开浏览器无论其类型如何,问题仅在于getelement,是否有办法在打开后处理浏览器?或者是否有其他方法来标识浏览器而不是ActiveXobject?即使您设法启动浏览器,它也不会返回对象模型来访问页面上的元素。我认为SeleniumWeb驱动程序可以满足这一需求。你可以试试看。