HtmlElementCollection.GetElementsByName(String) Method

Definition

Gets a collection of elements by their name.

public System.Windows.Forms.HtmlElementCollection GetElementsByName (string name);

Parameters

name
String

The name or ID of the element.

Returns

An HtmlElementCollection containing the elements whose Name property match name.

Examples

The following code example finds a FORM object using its name, and submits its data to the server programmatically. The code example requires that your application hosts a WebBrowser control named webBrowser1.

private void SubmitForm(String formName)
{
    HtmlElementCollection elems = null;
    HtmlElement elem = null;

    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        elems = doc.All.GetElementsByName(formName);
        if (elems != null && elems.Count > 0)
        {
            elem = elems[0];
            if (elem.TagName.Equals("FORM"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}

Remarks

While the Id property of an HtmlElement must be unique, multiple elements can use the same Name property.

Applies to

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9