2016-11-28 12 views
0

shell.applicationの組み合わせを使用して、関連するInternet Explorerを見つけ、UIAutomationを使用して、指定したページに表示されるファイルのダウンロードに対応するポップアップを処理しています。これは私が単一のインターネットエクスプローラを持っていた頃までうまくいった。今私はInternet Explorerの4つの異なるタブから同じことをしなければなりません。Internet Explorerでタブを選択

Shell.applicationプログラムの一部は素晴らしいです。しかし、UIAutomationを動作させるには、指定されたWebページを画面の前に配置する必要があります。私はこれが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を使ってタブimを抽出しました。

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の同じインスタンス内のタブとして別のWebページを開くのではなく、IEの別のインスタンスを開き、シェルを使用して関連Webページを前面に持って来ることです。アプリケーションは以下の2行です。

関連する問題