2016-11-28 115 views
0

我正在使用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 

回答

0

本身并不是一个答案,只是比评论更好的格式。我用下面的提取标签即时通讯使用SO。

Sub IEs() 

Dim x As ShellWindows 
Dim i As Integer 
Dim w As WebBrowser 

Set x = New ShellWindows 

For Each w In x 
    If w.LocationURL = "http://stackoverflow.com/questions/40846141/select-a-tab-in-internet-explorer" Then Exit For 
Next w 

End Sub 
+0

谢谢,但我想我可能找到了解决方案。打开IE的单独实例中的所有选项卡,然后使用ie.visible = false并再次使用ie.visible = true。必须对其进行测试。 –

+0

这样,我想在前面的IE浏览器出现...必须尝试,看看这个工程 –

0

我继续做我的研究,并在这里发帖的解决方案,我发现一个简单的解决方案。

我们所要做的只是在IE的同一实例中打开不同的网页作为选项卡,我们打开单独的IE实例,然后在使用shell找到它之后将相关的网页放到最前面。应用程序是以下两行。

ie.Visible = False 
ie.Visible = True 
相关问题