IE не обновляется после нажатия на ссылку - PullRequest
0 голосов
/ 16 сентября 2018

У меня есть простой код, который использует автоматизацию 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. Но когда я обновлялся до Windows 10 с IE 11, всегда LinkSet2 = LinkSet1 и бесконечный цикл происходит в части 3. Любая помощь будет принята с благодарностью заранее!

Ответы [ 2 ]

0 голосов
/ 17 сентября 2018

попробуйте

Set window.onload = GetRef("WindowLoad")
Function WindowLoad
  Dim oElm 
Set oElm = document.getElementById("MYSecondURL_id")
if oElm Is Nothing then
    MsgBox("element does not exist")
else        
   MsgBox("element does exist")
end if
End Function

Поскольку некоторые функции VBscript не работают в более новых версиях IE.И нет никаких сомнений в том, что IE является худшим исследователем в истории интернет-серфинга.

0 голосов
/ 16 сентября 2018

Это потому, что вы используете, пока ссылка не найдена.Это означает, что этот цикл никогда не закончится, если нет ссылки.Вместо.Я предлагаю вам использовать только для каждого цикла.И в конце цикла (когда цикл вышел.) Проверьте, найдена ли ссылка или нет.и выполните действие соответственно.

'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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...