没有 name属性的按钮如何点击,用webbrowser。
就像这个按钮
<INPUT onclick=check() type=button value="发 布">

解决方案 »

  1.   

     HtmlDocument doc = webBrowser1.Document;
    HtmlElementCollection coll = doc.GetElementsByTagName("input");
    foreach (HtmlElement item in coll)
       {
          if (item.GetAttribute("value") == "发 布")
           {
              item.InvokeMember("click");
            }
        }
      

  2.   

    HtmlDocument doc = webBrowser1.Document; foreach (HtmlElement em in doc.All) 
      { 
          if (item.GetAttribute("value") == "发 布") 
          { 
              item.InvokeMember("click"); 
            } 
        }
      

  3.   

    可以用 IEBrowser, 详情:http://code.google.com/p/zsharedcode/wiki/IEBrowserDocButtonClick下面是部分使用代码:// 创建 IEBrowser 对象, 用来控制窗口的 WebBrowser 控件.
    IEBrowser ie = new IEBrowser ( this.webBrowser );
    // 载入已经放在运行目录的页面 ButtonClick.htm.
    ie.Navigate ( Path.Combine ( AppDomain.CurrentDomain.BaseDirectory + "ButtonClick.htm" ) );// 等待 ButtonClick.htm 完全载入.
    ie.IEFlow.Wait ( new UrlCondition ( "wait", "ButtonClick.htm", StringCompareMode.EndWith ) );// 模拟具有惟一 id 属性的按钮点击.// 方法1: 执行 javascript 脚本来获取按钮并调用其 click 方法.
    ie.ExecuteScript ( "document.getElementById('cmdAdd').click();" );// 方法2: 安装跟踪和 jQuery 脚本后, 执行 jQuery 来模拟点击按钮.
    // 安装跟踪脚本.
    ie.InstallTrace ( );
    // 安装在资源中的 jQuery 脚本.
    ie.InstallScript ( Properties.Resources.jquery_1_5_2_min );
    // 执行获取按钮并模拟点击的 jQuery 脚本.
    ie.ExecuteJQuery ( JQuery.Create ( "'#cmdAdd'" ).Click ( ) );