• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 980
  • Last Modified:

Visual Basic, cannot Refresh an IE object (SHDocVw.InternetExplorer), throws exception

I have an application that first navigates to a website by invoking a separate IE browser window via calls to SHDocVw.InternetExplorer (project requirement is that the browser cannot be in the app). When oIE.Navigate is called the IE browser correctly goes to the requested page. A loop is called to check whether the page is fully loaded (certain HTML text) and if after 10 seconds it will try to refresh the page. However calls to oIE.Refresh generate an exception (Error HRESULT E_FAIL has been returned from a call to a COM component. StackTrace: at SHDocVw.IWebBrowser2.Refresh()  )  I have already implemented a loop to recheck the page's html code every 1/2 sec to wait for the page to update, but it continues to show the old page info.

The puzzling part of this is when I look at the browser window myself I do see that the page has fully loaded and the key phrase is in fact on the page, but oIE.Document.body.InnerHTML does not contain the phrase, just a old version of the page before the HTML was updated by javascript.

 Is there a way to tell the SHDocVw.InternetExplorer to get the new HTML from the IE browser window, or at least call Refresh?

1 Solution
Before refreshing the browser we have to use 'DoEvents' to give the browser enough time. If we do not use DoEvents oIE.Refresh generates the exception Error.

The oIe.ReadyState must be minimum 3. When the ReadyState is 3 or 4 the page is fully loaded and we can call the newest oIE.Document.body.InnerHTML

If oIe.ReadyState > 2 Then oIe.Refresh: Exit Do

Open in new window

tolvorAuthor Commented:
Excellent. Many thanks

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now