Clique em um link href em uma janela do navegador já aberta
No código abaixo, estou tentando clicar no link "Sobre" (href
) no site www.google.co.in. Isso funcionou no IE11 (Windows 10), mas não está funcionando no IE10 (Windows 7). Isso depende de qualquer maneira da máquina. Se não, qual é o código certo?
Lembre-se de que estou tentando clicar em um link em uma janela do navegador já aberta.
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
'You can use my_title of my_url, whichever you want
If my_title Like "Google" & "*" Then 'identify the existing web page
Set ie = ,objShell.Windows(x)
Exit For
Else
End If
Next
Dim LinkHref
Dim a
LinkHref = "//www.google.co.in/intl/en/about.html?fg=1"
For Each a In ie.Document.GetElementsByTagName("A")
If LCase(a.GetAttribute("href")) = LCase(LinkHref) Then
a.Click
Exit For ''# to stop after the first hit
End If
Next