Haga clic en un enlace href en una ventana del navegador ya abierta
En el siguiente código, intento hacer clic en el enlace "Acerca de" (href
) en el sitio web www.google.co.in. Esto funcionó en IE11 (Windows 10), pero no funciona para IE10 (Windows 7). ¿De todos modos esto depende de la máquina? Si no, ¿cuál es el código correcto?
Recuerde que estoy tratando de hacer clic en un enlace en una ventana del navegador ya abierta.
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