Нажмите на ссылку href в уже открытом окне браузера
В приведенном ниже коде я пытаюсь нажать на ссылку "О" (href
) на веб-сайте www.google.co.in. Это работало на IE11 (Windows 10), но не работает на IE10 (Windows 7). Это в любом случае зависит от машины. Если нет, то какой код правильный?
Пожалуйста, помните, что я пытаюсь нажать на ссылку в уже открытом окне браузера.
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