Donate

WebBrowser How To Fire Click Event Of Input Submit Element In C# And VB.NET

Given in a webpage there are several input elements and you want to fire the click event of an input element of type submit, here's how to do it using the Webbrowser control.
C#
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
HtmlElementCollection htmlElementCollection = new HtmlElementCollection();
if (WebBrowser1.Document != null) 
{
    htmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input");
    if (htmlElementCollection != null && htmlElementCollection.Count > 0)
    {
        foreach (HtmlElement element in htmlElementCollection) 
        {
            if (element.GetAttribute("value").Equals("Submit")) 
            {
                element.InvokeMember("click");
            }
        }
    }
}

VB.NET
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Dim htmlElementCollection As HtmlElementCollection
If (WebBrowser1.Document IsNot Nothing) Then
    With WebBrowser1.Document
        htmlElementCollection = .GetElementsByTagName("input")
        If (Not htmlElementCollection Is Nothing And htmlElementCollection.Count > 0) Then
            For Each element As HtmlElement In htmlElementCollection
                If (element.GetAttribute("value").Equals("Submit")) Then
                    element.InvokeMember("click")
                End If
            Next
        End If
    End With
End If

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input