Click here to Skip to main content
14,699,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Wait load webpage until element is present

I am new to c# and its concepts, so i am sorry if this question is kind of dumb. 
I try to do some automatation using the winforms webbrowser control.

I'm looking for a method that loads a web page until a web item is found.
to wait for the web page to load, I use line "Wait(30)"
"Wait(30)" this is an obvious expectation and this is not optimal.

I just need a synchronous download:
Find web item if the web item is missing on the page then wait 1 second, if the web item is found finish downloading a web page.


What I have tried:

private void Wait(int number)
{
    DateTime time = DateTime.Now;
    do
    {
        Application.DoEvents();
    }
    while (time.AddSeconds(number) > DateTime.Now);
}

private void CheckFindElement1()
{
    try
    {
	    Wait(30);
        var mlm = web_Browser.Document.GetElementById("id1");
    }
    catch (Exception)
    {
        Wait(1);
        CheckFindElement1();
    }
}
Posted
Updated 13-May-18 3:23am
v2
Comments
Richard MacCutchan 13-May-18 9:08am
   
That is not the right way to do it. You should add event handlers that will receive an event notification when the page load completes.

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