简体   繁体   中英

How to set the value of first input type text in document's first form using mshtml in C#?

I am trying to set the value of first input type text in document's first form. See the code below.

HTMLDocument htmldoc = new HTMLDocumentClass();  
htmldoc = (HTMLDocument)WebBrowser.Document;  
HTMLFormElement fm = (HTMLFormElement)htmldoc.forms.item(0); 

In the above code I am getting first form as a form object. Now I want to find the first input type text in this form and set the value of that textbox.

Any help would be appreciated.

loop in all elements in form

   private void button5_Click(object sender, EventArgs e)
    {
        var htmldoc = (HTMLDocument)webBrowser1.Document.DomDocument;
        HTMLFormElement fm = (HTMLFormElement)htmldoc.forms.item(0);
        foreach (IHTMLElement item in (IHTMLElementCollection)fm.all)
        {
            var textbox = item as IHTMLInputElement;
            if (textbox != null)
            {
                textbox.value = "your text";
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM