Simulate an onInput event from javascript

I’m testing an Elm form with selenium and whenever I change the value of a select, Elm doesn’t receive the event. So I am unable to simulate a real user selecting a different option in a dropdown.

I’ve tried triggering the event with javascript in the browser with no luck.

What’s the best way to do this?

The event for select is onchange. Try that!

So you mean something like the following?

$("#country").val("nl").trigger("onchange")

That doesn’t work. Meaning Elm doesn’t receive the event.

I figured it out. Here’s the code snippet that did it.

  var event = new Event('input', { 'bubbles': true, 'cancelable': true });
  var el = document.getElementById("country");
  el.dispatchEvent(event);
4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.