Internet Explorer automation not working with IE11

2019-09-09 21:51发布

I have some code that retrieves data from multiple websites via Internet Explorer automation in VBA. My code worked without problems with IE8, but in IE11, after the Navigate method of the Internet Explorer object is called, the Document and LocationURL are not updated; they still refer to the previously displayed website. Here's some code to reproduce the problem:

Sub Test()
    Debug.Print "start"
    Dim ie
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate "http://en.wikipedia.org/wiki/Visual_Basic"
    wait ie
    Debug.Print "Current URL: " & ie.LocationURL
    ie.Navigate "http://en.wikipedia.org/wiki/Microsoft_Office"
    wait ie
    Debug.Print "Current URL: " & ie.LocationURL
    Set ie = Nothing
End Sub

Sub Wait(ie As Variant)
    Do While ie.Busy
        Application.wait DateAdd("s", 1, Now)
    Loop
End Sub

When a run the above Test sub on a machine with IE8, it prints two different URLs, which is the expected behavior. However, when I run the same code on a machine with IE11, it prints the first URL twice. Any idea what might be wrong?

Update: I couldn't find a solution, so I went for the workaround of opening a new IE window for each URL.

2条回答
相关推荐>>
2楼-- · 2019-09-09 21:58

THX, You helped me. W7 Ultimate 64bit czech, IE11, VBA in Microstation V8i I use code like:

Public explorer As Object
....
Set explorer = CreateObject("InternetExplorer.Application")
....

If InStr(explorer.LocationURL, "CAPTCHA") = 0 Then
...
End If
查看更多
叛逆
3楼-- · 2019-09-09 22:19

I am not familiar with the VBA IE automation that you are using, however it sounds like you are hitting the same issue as Selenium WebDriver on IE11.

You may need to follow the same steps provided by the in the Selenium Wiki.

For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

http://code.google.com/p/selenium/wiki/InternetExplorerDriver

Hopefully that fixes your problem!

查看更多
登录 后发表回答