我正在使用shell.application的组合来查找我的相关Internet Explorer,然后使用UIAutomation来处理弹出窗口,该窗口用于在给定页面上给出的文件下载。这工作很好,直到我有一个单一的Internet Explorer。现在我必须从Internet Explorer的四个不同选项卡执行相同操作。选择Internet Explorer中的选项卡
该程序的Shell.application部分工作很好。但是为了使UIAutomation工作,给定的网页需要位于屏幕的前方。我想看看是否可以使用shell.application来实现,或者我愿意提供建议。
注意我做了很多搜索,但无法找到正确的内容。我粘贴了这两个代码。
'Connect with ApplicationName
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).document.Location
my_title = objShell.Windows(x).document.Title
If my_title Like "ApplicationName" & "*" Then
Set ie = objShell.Windows(x)
'ie.<<want some kind of select option >>
Exit For
Else
End If
Next
'Save download - this code does not work unless the Internet explorer is in the front
Application.Wait Now() + TimeSerial(0, 0, 5)
Dim o As IUIAutomation
Dim e As IUIAutomationElement
Set o = New CUIAutomation
Dim h As Long
h = ie.Hwnd
h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
If h = 0 Then Exit Sub
Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke
谢谢,但我想我可能找到了解决方案。打开IE的单独实例中的所有选项卡,然后使用ie.visible = false并再次使用ie.visible = true。必须对其进行测试。 –
这样,我想在前面的IE浏览器出现...必须尝试,看看这个工程 –