Click here to Skip to main content
15,884,880 members
Please Sign up or sign in to vote.
2.00/5 (1 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

1 solution

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:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx[^].

Alternatively, to get the same effect, override the virtual method System.Windows.Forms.WebBrowser.OnDocumentCompleted:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.ondocumentcompleted.aspx[^].

"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.

—SA
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900