Internet explorer 用于填充IE字段的VBS脚本:难以使用iFrame

Internet explorer 用于填充IE字段的VBS脚本:难以使用iFrame,internet-explorer,iframe,vbscript,field,populate,Internet Explorer,Iframe,Vbscript,Field,Populate,我定期向第三方数据库输入数据。我正在尝试制作一个简单的VBscript,它将从我自己的Excel电子表格中提取数据,并将其放入internet explorer上的第三方输入表单中。这个过程正在运行,除非我在报名表上看到一个iframe。非常感谢您在这方面的帮助。我是个新手 在启动VBS(长话短说)之前,我需要表单已经打开,因此我的脚本需要查找打开的页面。我已经找到了一个这样做的脚本。我创建了一个演示输入系统,如下所示: index.htm <html> <body>

我定期向第三方数据库输入数据。我正在尝试制作一个简单的VBscript,它将从我自己的Excel电子表格中提取数据,并将其放入internet explorer上的第三方输入表单中。这个过程正在运行,除非我在报名表上看到一个iframe。非常感谢您在这方面的帮助。我是个新手

在启动VBS(长话短说)之前,我需要表单已经打开,因此我的脚本需要查找打开的页面。我已经找到了一个这样做的脚本。我创建了一个演示输入系统,如下所示:

index.htm

<html>
<body>

<p>First input box is on the_index.htm (main document).</p>
<input id="title" name="title-1" style="width: 220px;" title="enter title" type="text" value="">

<br /><br /><br /><br />
<iframe frameborder="0" id="input_frame" marginheight="0" marginwidth="0" name="input_frame" src="the_iframe.htm">

</body>
</html>
<html>
<body>
<p>Second input box is on the_iframe.htm (iframe called from the main document).</p>
<input id="title" name="title-1" style="width: 220px;" title="enter title" type="text" value="">
</body>
</html>
“wheee1”部署工作正常,但wheee2生成的“对象不支持此属性或方法:'ie.document.frames(…).All'。如果我去掉了“.All”,那么错误是“member not found”


有人能告诉你这里是否有一个简单的修复方法吗?

你可以通过
IE.Document.frames(“input\u frame”)
获得框架窗口。因为它不是一个文档,所以您也需要将
文档
包含在此地址中。

IE.Document.Frames("input_frame").Document.All("title").Value = "wheee2"

我明白这是一个o;但对于任何一个在这里挣扎的人来说,我使用的是“小”的解决方案

要获得打开的窗口,这仅在您使用IE查看时有效,firefox等未注册此代码:

 For Each AW in CreateObject("Shell.Application").Windows 
'AW=活动窗口

'这将拾取打开的窗口文件夹,并在没有此选项的情况下崩溃 检查

另外,与Excel接口的对象是:

Set xl = CreateObject("Excel.Application")
你可以打电话给xl。您可以使用普通的vba命令

xl.workbook().worksheets().cells().value etc
IFrame部分——这一部分的难点在于它是一个窗口对象,而不是一个文档对象

因此,您拥有活动窗口,并且希望导航到iframe:

Set iFra = AW.Document.GetElementById(<String - iframe id>)
获得iframe后,需要使用.ContentWindow属性

所以从上面看iFra.ContentWindow

可以像AW1一样使用它们来获取所有嵌套属性

乙二醇

iFra.ContentWindow.Document.GetElementById().Value=“排序”
注意:使用此选项时,如果内容刷新,则需要重新抓取iframe对象(上面的Set IFra命令)

使用IE developer(即默认情况下为f12)时的一个有用提示当查看html时,在iframe中激活所需的字段,然后在developer中刷新html,然后您应该能够使用带有ifram内容的get元素

Set oIe = CreateObject("InternetExplorer.Application")
Set xl = CreateObject("Excel.Application")
xl.workbook().worksheets().cells().value etc
Set iFra = AW.Document.GetElementById(<String - iframe id>)
For each iFra in AW.Document.GetElementsByTagName("iframe")
  iFra...
Next
iFra.ContentWindow.Document.GetElementById(<String - ID>).Value = "Sorted"