本文介绍了我无法理解在C#中实现documentCompleted的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,所以我无法执行以下操作:

i想检查网页是否已加载到webBrowser(C#)中,以便我可以填写字段,如果页面有copmletely加载。以下是我希望一个接一个地完成后运行它们的两种方法:

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:

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如果我正朝着正确的方向解决问题,但它无效。 。

1我想检查页面是否已加载主页,当它被加载时,我正在做一些逻辑来填充字段,它应该登录。当成功登录完成后我我试图去另一个页面(相同的登录帐户)。因此,我必须检查文档是否已完成加载,以便我可以在下一页继续进行。



请告诉我如何做到这一点,因为我新的。

问候。


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.

推荐答案


private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(url);
            t = 0;
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(login);

            //login();
        }










private void login(object sender,WebBrowserDocumentCompletedEventArgs e)
        {

            //logic here
        }













private void checkPage()
        {

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

         

        }


这篇关于我无法理解在C#中实现documentCompleted的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:39