以编程方式将文本输入到网站文本字段

时间:2017-04-04 18:22:37

标签: c# html

如果你告诉我为什么它不起作用会很感激。当我按下按钮时没有任何反应。

//    <input type="text" name="nick" value="" size="25" tabindex="1" maxlength="50" class="material-input" required="">

  private void loginName()
    {     
        HtmlElementCollection classButton = webBrowser1.Document.All;
        foreach (HtmlElement element in classButton)
        {
            if (element.GetAttribute("material-input") == "input")
            {
                element.SetAttribute("name", "abcdfefefefe");
            }
        }    
    }
    private void button1_Click(object sender, EventArgs e)
    {
        loginName();
    }

编辑: 这是一个很好的解决方案吗?

  var loginElement = webBrowser1.Document.GetElementsByTagName("input")["nick"];
        passwordElement.SetAttribute("value", "abcdfefefefe");

0 个答案:

没有答案