The following sample demonstrates how to set the values of the form input elements (text field or check box). The same approach will also work if there is no form.


WPF

C#

using DotNetBrowser;
using DotNetBrowser.DOM;
using DotNetBrowser.Events;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace DOMFormSample
{
    class Program
    {
        public class WindowMain : Window
        {
            private WPFBrowserView browserView;

            public WindowMain()
            {
                Browser browser = BrowserFactory.Create();
                browserView = new WPFBrowserView(browser);

                browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
                {
                    if (e.IsMainFrame)
                    {
                        DOMDocument document = e.Browser.GetDocument();
                        DOMInputElement firstName = (DOMInputElement)document.GetElementByName("firstName");
                        DOMInputElement lastName = (DOMInputElement)document.GetElementByName("lastName");
                        DOMInputElement agreement = (DOMInputElement)document.GetElementByName("agreement");
                        firstName.Value = "John";
                        lastName.Value = "Doe";
                        agreement.Checked = true;
                    }
                };

                Content = browserView;

                Width = 1024;
                Height = 768;
                this.Loaded += WindowMain_Loaded;
            }

            void WindowMain_Loaded(object sender, RoutedEventArgs e)
            {
                browserView.Browser.LoadHTML("<html><body><form name=\"myForm\">" +
                "First name: <input type=\"text\" name=\"firstName\"/><br/>" +
                "Last name: <input type=\"text\" name=\"lastName\"/><br/>" +
                "<input type='checkbox' name='agreement' value='agreed'>I agree<br>" +
                "<input type=\"button\" value=\"Save\"/>" +
                "</form></body></html>");
            }

            [STAThread]
            public static void Main()
            {
                Application app = new Application();

                WindowMain wnd = new WindowMain();
                app.Run(wnd);

                var browser = wnd.browserView.Browser;
                wnd.browserView.Dispose();
                browser.Dispose();
            }
        }
    }
}

VB.NET

Imports System.Windows
Imports DotNetBrowser
Imports DotNetBrowser.DOM
Imports DotNetBrowser.WPF

Module Module1
    Public Class WindowMain
        Inherits Window

        Public Dim browserView As WPFBrowserView

        Public Sub New()
            Dim browser As Browser = BrowserFactory.Create()
            browserView = New WPFBrowserView(browser)

            AddHandler browser.FinishLoadingFrameEvent, sub(o, e)
                If e.IsMainFrame Then
                    Dim document As DOMDocument = e.Browser.GetDocument()
                    Dim firstName As DOMInputElement = CType(document.GetElementByName("firstName"), DOMInputElement)
                    Dim lastName As DOMInputElement = CType(document.GetElementByName("lastName"), DOMInputElement)
                    Dim agreement As DOMInputElement = CType(document.GetElementByName("agreement"), DOMInputElement)
                    firstName.Value = "John"
                    lastName.Value = "Doe"
                    agreement.Checked = True
                End If
            End sub

            Content = browserView

            Width = 1024
            Height = 768
            AddHandler Me.Loaded, AddressOf WindowMain_Loaded
        End Sub

        Private Sub WindowMain_Loaded(sender As Object, e As RoutedEventArgs)
            browserView.Browser.LoadHTML("<html><body><form name=""myForm"">" +
                                         "First name: <input type=""text"" name=""firstName""/><br/>" +
                                         "Last name: <input type=""text"" name=""lastName""/><br/>" +
                                         "<input type='checkbox' name='agreement' value='agreed'>I agree<br>" +
                                         "<input type=""button"" value=""Save""/>" +
                                         "</form></body></html>")
        End Sub
    End Class

    <STAThread>
    Sub Main()
        Dim app As Application = New Application()

        Dim wnd As WindowMain = New WindowMain()
        app.Run(wnd)

        Dim browser = wnd.browserView.Browser
        wnd.browserView.Dispose()
        browser.Dispose()
    End Sub
End Module


WinForms

C#

using System;
using System.Windows.Forms;
using DotNetBrowser;
using DotNetBrowser.DOM;
using DotNetBrowser.Events;
using DotNetBrowser.WinForms;

namespace DOMFormSample
{
    class Program
    {
        public class WindowMain : Form
        {
            private WinFormsBrowserView browserView;

            public WindowMain()
            {
                Browser browser = BrowserFactory.Create();
                browserView = new WinFormsBrowserView(browser);

                browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e)
                {
                    if (e.IsMainFrame)
                    {
                        DOMDocument document = e.Browser.GetDocument();
                        DOMInputElement firstName = (DOMInputElement)document.GetElementByName("firstName");
                        DOMInputElement lastName = (DOMInputElement)document.GetElementByName("lastName");
                        DOMInputElement agreement = (DOMInputElement)document.GetElementByName("agreement");
                        firstName.Value = "John";
                        lastName.Value = "Doe";
                        agreement.Checked = true;
                    }
                };

                this.Controls.Add(browserView);

                Width = 1024;
                Height = 768;
                this.Load += WindowMain_Loaded;
            }

            void WindowMain_Loaded(object sender, EventArgs e)
            {
                browserView.Browser.LoadHTML("<html><body><form name=\"myForm\">" +
                "First name: <input type=\"text\" name=\"firstName\"/><br/>" +
                "Last name: <input type=\"text\" name=\"lastName\"/><br/>" +
                "<input type='checkbox' name='agreement' value='agreed'>I agree<br>" +
                "<input type=\"button\" value=\"Save\"/>" +
                "</form></body></html>");
            }

            [STAThread]
            public static void Main()
            {
                WindowMain wnd = new WindowMain();
                Application.Run(wnd);

                var browser = wnd.browserView.Browser;
                wnd.browserView.Dispose();
                browser.Dispose();
            }
        }
    }
}

VB.NET

Imports System.Windows
Imports System.Windows.Forms
Imports DotNetBrowser
Imports DotNetBrowser.DOM
Imports DotNetBrowser.WinForms

Module Module1
    Public Class WindowMain
        Inherits Form

        Public Dim browserView As WinFormsBrowserView

        Public Sub New()
            Dim browser As Browser = BrowserFactory.Create()
            browserView = New WinFormsBrowserView(browser)
            browserView.Dock = DockStyle.Fill

            AddHandler browser.FinishLoadingFrameEvent, sub(o, e)
                If e.IsMainFrame Then
                    Dim document As DOMDocument = e.Browser.GetDocument()
                    Dim firstName As DOMInputElement = CType(document.GetElementByName("firstName"), DOMInputElement)
                    Dim lastName As DOMInputElement = CType(document.GetElementByName("lastName"), DOMInputElement)
                    Dim agreement As DOMInputElement = CType(document.GetElementByName("agreement"), DOMInputElement)
                    firstName.Value = "John"
                    lastName.Value = "Doe"
                    agreement.Checked = True
                End If
            End sub

            Controls.Add(browserView)

            Width = 1024
            Height = 768
            AddHandler Me.Load, AddressOf WindowMain_Loaded
        End Sub

        Private Sub WindowMain_Loaded(sender As Object, e As EventArgs)
            browserView.Browser.LoadHTML("<html><body><form name=""myForm"">" +
                                         "First name: <input type=""text"" name=""firstName""/><br/>" +
                                         "Last name: <input type=""text"" name=""lastName""/><br/>" +
                                         "<input type='checkbox' name='agreement' value='agreed'>I agree<br>" +
                                         "<input type=""button"" value=""Save""/>" +
                                         "</form></body></html>")
        End Sub
    End Class

    <STAThread>
    Sub Main()
        Dim wnd As WindowMain = New WindowMain()
        Forms.Application.Run(wnd)

        Dim browser = wnd.browserView.Browser
        wnd.browserView.Dispose()
        browser.Dispose()
    End Sub
End Module