Search code examples
c#geckofx

Other text input methods?


There are a bunch of websites with "search" input boxes.
If I input a word manually then it automatically search without need to click any buttons.

Using the following code:

             GeckoInputElement input = (GeckoInputElement)geckoHtmlElement;
             input.Value = "searchword";

The I see that search input box is filled but nothing happens automatically.
If I manually add space or any character then website works as expected.
Auto searches my wanted word.

I tried using input.Focus(); but still same.
Any ideas how I can input text into search box in a more advanced way or something like that?


Solution

  • I think the solution here is to manually trigger the event that triggers the search - for example the keyup event. I had the same problem which I solved by adding this code:

        nsAStringBase eventType = (nsAStringBase)new nsAString("keyup");
                var ev = browser.Document.CreateEvent("HTMLEvents");
                ev.DomEvent.InitEvent(eventType, false, false);
    nameBox.GetEventTarget().DispatchEvent(ev);
    

    You would need to inspect your page and see if there are any javascript events attached to your input. Good luck!