首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WebBrowser模拟鼠标点击网页超链接,一直没有生效,求大神指点迷津!解决方案

2013-12-19 
WebBrowser模拟鼠标点击网页超链接,一直没有生效,求大神指点迷津!!!一下是代码:private void Start(object

WebBrowser模拟鼠标点击网页超链接,一直没有生效,求大神指点迷津!!!
一下是代码:
private void Start(object sender, EventArgs e)//  定义一个按钮点击
        {
            
            webForm.Url = new System.Uri("http://www.baidu.com"); 
            HtmlDocument doc = webForm.Document;
            HtmlElementCollection items = doc.GetElementsByTagName("a");
            foreach (HtmlElement el in items)
            {
                string text = el.GetAttribute("InnerText").ToString().Trim();
                if (text == "登录")
                {
                    el.InvokeMember("onclick");                                
                    break;
                }
            }
            
        }

怎么执行后,在winform中的百度主页就是没有跳出登陆窗口?看了下其他人写的,没什么区别啊,怎么我的就是无法生效?求各位大神指点。。
[解决办法]
     WebForm.Navigate("http://www.baidu.com");
     while (WebForm.ReadyState != WebBrowserReadyState.Complete)
     Application.DoEvents();
     WebForm.Document.GetElementById("kw").InnerText = "金庸";
     WebForm.Document.GetElementById("su").InvokeMember("click");

热点排行