Click here to Skip to main content
13,252,206 members (55,967 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hey guys,
When I'm working with webbrowser and I want to let my application navigate to url and for example click a button right after that how should I do that? The problem is that my apps always perform all the commands too quickly and it mostly ends up with my app not being able to find the element by id because web page is still not loaded. Well I tried to use timers and it seems to work but when I'm trying to do apps which I need to navigate on more webpages, then clicking the buttons I just get too many timers and its confusing. I'm pretty sure there must be some way to make some kind of delay to wait until the page loads, then execute the commands. Already tried DocumentCompleted event based on webbrowser's url but it seems to create infinite loop. I was thinking about Sleep() but it makes your app freeze for certain time so that's propably not what I'm looking for. I have no idea how to solve this issue without creating that many timers. Can anybody please help?
Posted 3-Apr-13 10:09am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

IF course, any kinds of delay for a fixed amount of times are completely pointless, not just slow.

It looks like you need to handle the event System.Windows.Forms.WebBrowser.DocumentCompleted:[^].

Alternatively, to get the same effect, override the virtual method System.Windows.Forms.WebBrowser.OnDocumentCompleted:[^].

"After navigation" may be not what you want (but of course, there is an appropriate event you can handle), because it is invoked at the moment of time when a document only starts to load.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100