我有一个简单的代码,该代码使用IE自动化工具登录到网站(例如URL1),然后单击链接(例如URL2),然后等待新页面准备就绪,依此类推。 这是代码:
'Part 1: Navigating to URL1
IE = CreateObject("InternetExplorer.Application")
IE.visible = True
IE.Navigate(URL1)
Do Until IE.ReadyState = tagREADYSTATE.READYSTATE_COMPLETE
Application.DoEvents()
Loop
LinkSet1 = IE.document.all'Storing the current page's links only to help asking my question clearer :)
'Part 2: Entering user name and password and submit
IE.Document.All("UserNameElementID").InnerText = MyUserName
IE.Document.All("PasswordElementID").InnerText = MyPassword
IE.Document.All("SubmitElementID").click
Do Until IE.ReadyState = tagREADYSTATE.READYSTATE_COMPLETE
Application.DoEvents()
Loop
'Part 3: Search through links to detect a special id on the second page (URL2)
LinkFound = False
Do Until LinkFound
LinkSet2 = IE.document.all'Storing the new page's links only to help asking my question clearer :)
For Each Link In IE.document.all
If InStr(Link.id, "MYSecondURL_id") > 0 Then
LinkFound = True
Exit For
End If
Next
Loop
'Part 4: Send a message to show that the second URL is found
MsgBox("Page loaded completely!")
我的问题是,当我将Windows 7与IE 10一起使用时,上面的代码可以正常工作,但是当我使用IE 11更新到Windows 10时,始终是LinkSet2 = LinkSet1,并且在第3部分出现无限循环。提前!
答案 0 :(得分:0)
这是因为您使用的是直至找到链接。这意味着如果没有链接,此循环将永远不会结束。代替。我建议您只为每个循环使用。并在循环结束时(退出循环时)检查是否找到链接。并据此执行操作。
'Part 3: Search through links to detect a special id on the second page (URL2)
LinkFound = False
LinkSet2 = IE.document.all
For Each Link In IE.document.all
If InStr(Link.id, "MYSecondURL_id") > 0 Then
LinkFound = True
Exit For
End If
Next
If LinkFound=True
'Do what you want to do if there is link
else
'Do when there is no link in the page
End If
答案 1 :(得分:0)
尝试
private
因为某些VBscript函数在较新版本的IE上不起作用。 毫无疑问,IE是互联网浏览历史上最糟糕的浏览器。