Forum Discussion

simonaferrara's avatar
simonaferrara
Frequent Contributor
4 years ago
Solved

The dispatchEvent browser method doesn't work

Hi all,

 

in a web test (I'm using JavaScript), I want to use the "dispatchEvent" browser method to dispatch a browser-specific event or a custom event created on the browser.

 

As simple examples (just to try how to use the method), I've tried to dispatch a "pointerdown" and then a "pointerup" after a delay, or I to do a click on a button using this dispatchEvent method.

 

I've tried this code:

   canvas.dispatchEvent("pointerdown");
   Delay(600);
   canvas.dispatchEvent("pointerup");

 

and 

  button.dispatchEvent("click");

 

But it doesn't work. Nothing appens in the browser, as if the browser doesn't receive the event.

 

How can I use this method? Can you please explain me with some examples?

 

Thanks

Simona

5 Replies

    • simonaferrara's avatar
      simonaferrara
      Frequent Contributor

      Thanks AlexKaras, the link that you send me is an interesting topic, and it could be interesting also for future purposes. We will try to investigate and use this approach if needed.

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Alex, Marsha, thanks a lot!

       

      simonaferrara were you able to solve this? If not, let's keep the community investigation going - please provide the info Alex is asking about. Thanks. 

    • simonaferrara's avatar
      simonaferrara
      Frequent Contributor

      Thanks Marsha_R , I had already though to initialize a variable as a new "Event" (as in the example that you've linked), but Test Complete doesn't recognize the DOM "Event" class. When I run the test, the following Javascript runtime error is displayed: "ReferenceError: Event is not defined". 

      There could be some configurations to be done on the project, or something that could be referenced by the project, to have the DOM classes visible?