Search code examples
c#javascripthtmlgeckofx

Gecko Browser wont fill inputs on load


I've got this little collection of all the Inputs on the loaded site. The program searches for a text input that is specified by a list of html names

GeckoElementCollection _Ellements = geckoWebBrowser1.Document.GetElementsByTagName("input");

The Problem is that it wont fill the textbox

foreach (GeckoElement _e in _Ellements)
{
    if (_e.GetAttribute("value") == "username")
    {
        _e.SetAttribute("selected", "Username Here");
    }
}

Please help me I've been trying to fix this for ages


Solution

  • Here is some example code that sets the value of all inputs then document has finished loading.

    Of course 'inputs' can be of different types (like Buttons, Text boxes, radio buttons) so in you would want to check the the type attribute as well.

    browser.DocumentCompleted += (s, e) =>
    {
    
     GeckoElementCollection elements = browser.Document.GetElementsByTagName("input");
     foreach (var element in elements)
     {
      GeckoInputElement input = (GeckoInputElement) element;
      input.Value = "Auto filled!";
     }
    };