从 shell.application 对象创建 Internet Explorer 变量
Create Internet Explorer variable from shell.application object
我正在检索一个活动的 Internet Explorer 选项卡以 运行 一个已验证站点的自动化脚本。我需要将应用程序实例本身作为要操作的东西,因为我有办法导航到我想要的页面,因为按钮没有 ID 来调用它。
我首先在这里找到正确的页面,然后从那里一切顺利。
Dim oShell, oWSHShell, sTitle, wndw, bMatch, oSelect
set oShell =createobject("shell.application")
set oWSHShell = createobject("wscript.shell")
sHTMLTitle = "Add Account"
bMatch =false
for each wndw in oShell.windows
if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then
sTitle =wndw.document.title
if Instr(sTitle, sHTMLTitle)<> 0 then
bMatch =true
exit for
end if
end if
next
有没有办法可以将 oShell 对象保存为我以后可以引用的对象?我看到的任何关于声明 IE 对象的参考都是为了制作一个全新的 window,这在这里不起作用,因为您必须重新验证自己并破坏整个目的。
如果我理解正确,那么根据您的评论,我认为您的方向是正确的。 wndw
是您的 IE 对象。但是在分配对象引用时需要使用 Set
关键字。例如:
Set objSaveIE = Nothing
for each wndw in oShell.windows
if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then
sTitle =wndw.document.title
if Instr(sTitle, sHTMLTitle)<> 0 then
Set objSaveIE = wndw
exit for
end if
end if
next
' Now you can use objSaveIE as you would any other IE object...
If Not objSaveIE Is Nothing Then objSaveIE.Navigate "www.google.com"
我正在检索一个活动的 Internet Explorer 选项卡以 运行 一个已验证站点的自动化脚本。我需要将应用程序实例本身作为要操作的东西,因为我有办法导航到我想要的页面,因为按钮没有 ID 来调用它。
我首先在这里找到正确的页面,然后从那里一切顺利。
Dim oShell, oWSHShell, sTitle, wndw, bMatch, oSelect
set oShell =createobject("shell.application")
set oWSHShell = createobject("wscript.shell")
sHTMLTitle = "Add Account"
bMatch =false
for each wndw in oShell.windows
if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then
sTitle =wndw.document.title
if Instr(sTitle, sHTMLTitle)<> 0 then
bMatch =true
exit for
end if
end if
next
有没有办法可以将 oShell 对象保存为我以后可以引用的对象?我看到的任何关于声明 IE 对象的参考都是为了制作一个全新的 window,这在这里不起作用,因为您必须重新验证自己并破坏整个目的。
如果我理解正确,那么根据您的评论,我认为您的方向是正确的。 wndw
是您的 IE 对象。但是在分配对象引用时需要使用 Set
关键字。例如:
Set objSaveIE = Nothing
for each wndw in oShell.windows
if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then
sTitle =wndw.document.title
if Instr(sTitle, sHTMLTitle)<> 0 then
Set objSaveIE = wndw
exit for
end if
end if
next
' Now you can use objSaveIE as you would any other IE object...
If Not objSaveIE Is Nothing Then objSaveIE.Navigate "www.google.com"