用c# webbrowser 编写自动签到

遇到的问题、要点

1、阻止页面弹出js错误对话框

  private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true;            
        }

2、自动填写文本框报错

自动填写文本框时报错,提示没有找到文本框。解决办法是,要等页面加载完毕后才能去寻找

  private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
             HtmlElement username = webBrowser1.Document.GetElementById("kw");
            //判断是否找到了目标文本框,如果没找到,应该是网页跳转过了。
            //此处是否也可以用html title来判断网页?确定是要访问的网页再去寻找目标
            if (username == null )
                return;            
        }

3、程序在跳转多个网址时,非同步。

在要轮流跳转多个网址的时候,没等到第一个网页加载完毕,就已经跳转第二个网页了,而且每次签到成功都会有个确认框,这个确认框用代码覆盖也没用,

function alert()={}

不知道后台是怎么调用的。最后只能在一个form1里面跑逻辑,在另外一个form2里面加载网页,form2加载完毕并执行动作后,自动关闭。

发布了14 篇原创文章 · 获赞 1 · 访问量 6687

猜你喜欢

转载自blog.csdn.net/weixin_43833645/article/details/103549349
今日推荐