Set Attribute of DOM-Element in C# With the webBrowser in Windows Forms

32 Views Asked by At

I want to fill out a loginwebpage from a webbrowser in WindowsForms. This is my code som far:

public Form1()
        {
            InitializeComponent();
            webBrowser.DocumentCompleted += new        WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
            webBrowser.Navigate("https://www.loginpage.com");
        }

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            // Check if the document is fully loaded
            if (webBrowser.ReadyState == WebBrowserReadyState.Complete)
            {
                
                HtmlElement inputElement = webBrowser.Document.GetElementById("passwordField");

                // Set the attribute, for example, change the value attribute
                if (inputElement != null)
                {
                    inputElement.SetAttribute("Value", "New Value");
                }
            }
        }

I cant fill out the element. I checked and the webpage is laoded completely and i can get attributes inside the webBrowser_DocumentCompleted-function but i cant set attributes.

0

There are 0 best solutions below