<INPUT id=abc type=file>
需要 添加成这样<INPUT id=abc type=file value=abc>
请问用webbrowser 如何来实现呢?
由于vale这个属性本来就没有设置,所有SetAttribute 是不行的。。

解决方案 »

  1.   

    HtmlElement htmlA = webBrowser1.Document.CreateElement("A");
    HtmlElement htmlFont = webBrowser1.Document.CreateElement("FONT");
    htmlA.SetAttribute("href", "");
    htmlA.Click += new HtmlElementEventHandler(htmlItem_Click);
    htmlFont.SetAttribute("color", string.Format("rgb({0},{1},{2})", c.R, c.G, c.B));
    htmlFont.InnerText = "";
    htmlA.AppendChild(htmlFont);
      

  2.   

    <INPUT id=abc type=file>
    这个input是在页面中的元素,不是我自己创建的哦, 我这样写HtmlElement value=webBrowser1.Document.CreateElement("value");
    value.InnerText = "";
    webBrowser1.Document.GetElementById("abc").AppendChild(value);
    用你的方法添加value后报错:提示value值不在预期的范围内。
      

  3.   

    假设HTML源代码如下:
    <html>
    <body>
    <input type="button" id="btnClose" value="关闭" />
    </body>
    </html>这样就可以拿到id为btnClose的元素了!
    HtmlDocument htmlDoc = webBrowser.Document;
    HtmlElement btnElement = htmlDoc.All["btnClose"];又比如拿到用户名和密码的输入框,输入值
    HtmlElement tbUserid = webBrowser.Document.All["username"];
    HtmlElement tbPasswd = webBrowser.Document.All["password"];
    if (tbUserid == null || tbPasswd == null || btnSubmit == null)
        return;
    tbUserid.SetAttribute("value", "smalldust");
    tbPasswd.SetAttribute("value", "12345678");
      

  4.   

    回楼上的,这些我都知道。。问题是 页面的代码为<INPUT id=abc type=file>
    压根就没有value属性呀怎么设置,用SetAttribute("value", "12345678")的时候,就会value值不在预期的范围内。
      

  5.   

    嗯,是我理解错了, 查了msdn ,有如下描述HTML 中的属性是此元素的任何有效名称/值对。HtmlElement 仅公开所有元素共用的那些属性,而忽略仅适用于某些元素类型的那些属性。例如,SRC 是 IMG 标记的预定义属性,但不是 DIV 标记的属性。使用 GetAttribute 和 SetAttribute 操作未在托管文档对象模型 (DOM) 中公开的属性。如果元素中未定义 attributeName 属性,则 SetAttribute 将在元素中将其作为新属性加以定义。
    看来就算页面元素没有attributeName ,用SetAttribute  也是可以设置的,看来是我其他地方错了,谢谢大家了