Как выбрать вкладки IE после симуляции клика - PullRequest
0 голосов
/ 01 июля 2019

Я делаю простой скрипт, который может открыть сайт, найти кнопку, нажать на нее (открыть новую вкладку) и найти данные на новой вкладке.Я заблокирован в точке сброса: как я могу получить доступ к данным на новой вкладке?Большое спасибо!

Sub testWebOpenTabAndFocus()    
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    ' open new IE window
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    ' Send the form data To URL As POST binary request
    IE.navigate "somesite.com"

    '..... some code to search about a button

    objElement.Click    ' click button to load a new tab

    ' Wait while IE re-loading...
    While IE.Busy
            DoEvents
    Wend

    ' finding the new tab with Windows(x)

    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_title = objShell.Windows(x).Document.Title
        If my_title Like "*Analysis Application*" Then 
            Set IE = objShell.Windows(x) 'this is my new tab
        End If
    Next

    'Some code to be runned on the new tab
    'but its not working because it still has the focus on previous tab

    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
End Sub

1 Ответ

2 голосов
/ 01 июля 2019

Попытка заменить приведенную ниже часть кода в приведенном выше коде может помочь решить проблему.

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
         If x.Name = "Internet Explorer" And TypeName(x.document) = "HTMLDocument" Then
        my_title = objShell.Windows(x).document.Title
        Debug.Print (my_title)
        If my_title Like "*Analysis Application*" Then
            Set IE = objShell.Windows(x) 'this is my new tab
        End If
         End If
    Next

Если проблема не устранена, попробуйте предоставить подробную информацию, например, в какой строке вы получаете ошибку или застряли тамс сообщением об ошибке может дать нам больше представление о проблеме.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...