在下面的代码中,我尝试单击www.google.co.in网站上的“关于”链接(href
)。这适用于IE11(Windows 10),但不适用于IE10(Windows 7)。这是否依赖于机器。如果不是什么是正确的代码?单击已打开的浏览器窗口中的href链接
请记住我试图点击已打开的浏览器窗口中的链接。
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
如果您使用的是QTP,也许使用内置的浏览器自动化和一些描述性编程会更简单,甚至只是使用对象库来了解您的目标站点并导航它?最好的方法将取决于你的脚本的总体目标,虽然 – Dave
什么是__如果my_title像“谷歌”和“*”然后'__Like__? – SearchAndResQ
奇怪....但它确实工作,因为我在我的Win10 IE11浏览器上说过 –