Simulate an onInput event from javascript

#1

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?

#2

The event for select is onchange. Try that!

#3

So you mean something like the following?

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

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

#4

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);
2 Likes
closed #5

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