Click here to Skip to main content
15,881,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am new to this so i am unable to do the following:
i want to check if the webpage is loaded in webBrowser(C#) so that i can fill the fields if the page has copmletely loaded. Here are the two methods i want to run them one after the other is completed:
C#
private void button1_Click(object sender, EventArgs e)
        {
            login();   
        }

        private void login()
        {
            checkPage();
            //login logic will come in this method
        }

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
       {
           if (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete)
           {
               return;
           }
           else
           {
               checkPage();
           }
       }

int a = 0;
        private void checkPage()
        {

            if (webBrowser1.Url.AbsoluteUri == url2)
            {
                webBrowser1.Navigate(url1);

            }

            else if (a == 0)
            {

                webBrowser1.Navigate(url);
                a++;

            }

        }

i dont if i am going in right direction to solve the problem but its not working..
1st i want to check if the page has loaded the home page, when it is loaded then i am doing some logic to fill the fields and it should log in. when the successful login is done i am trying to go on another page (of the same logged in account). So for this i have to check that the document has completed loading so that i can do further on the next page.

Kindly tell me how to do that as i am new to this.
Regards.
Posted
Updated 14-Apr-13 2:25am
v2

The DocumentCompleted event occurs when the document is fully loaded, so you can access the contents through the Document, DocumentText, or DocumentStream properties.

WebBrowser.DocumentCompleted Event[^]

The WebBrowser has a Document property returning an HtmlDocument[^]. You can use the HtmlDocument.GetElementById[^] to acess elements by id. You then use the returned HtmlElement[^] to manipulate that element.


Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Member 9357064 14-Apr-13 9:11am    
This is exectly i am trying to know that how to do that? kindly help in the code part.
regards..
Sergey Alexandrovich Kryukov 25-Apr-13 18:53pm    
I voted 5, but later, looking at the question, felt not sure if OP is getting it...
—SA
Espen Harlinn 25-Apr-13 18:57pm    
Which is why I later added a link to GetElementById and HtmlElement - anyway thank you, Sergey :-D
Sergey Alexandrovich Kryukov 25-Apr-13 19:00pm    
Right...
C#
private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(url);
            t = 0;
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(login);

            //login();
        }



C#
private void login(object sender,WebBrowserDocumentCompletedEventArgs e)
        {

            //logic here
        }




C#
private void checkPage()
        {

                webBrowser1.Navigate(url2);
                webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(othetMethods);
                

         

        }
 
Share this answer
 

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