cancel
Showing results for 
Search instead for 
Did you mean: 

The dispatchEvent browser method doesn't work

SOLVED
Highlighted
Occasional Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: The dispatchEvent browser method doesn't work

Hi Simona,

 

Can you provide more details why you need this? Can you describe scenario when regular .Click() method provided by TestComplete does not work?

 

P.S. https://support.smartbear.com/articles/testcomplete/embedding-scripts-into-web-pages/ might appear to be an inspiring reading...

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: The dispatchEvent browser method doesn't work

That's not a TestComplete method, so you might want to look elsewhere for help.  I found this on Google but there might be better resources.

https://javascript.info/dispatch-events

Highlighted
Occasional Contributor

Re: The dispatchEvent browser method doesn't work

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?

 

Highlighted
Community Hero

Re: The dispatchEvent browser method doesn't work

Hi Simona,

 

Can you provide more details why you need this? Can you describe scenario when regular .Click() method provided by TestComplete does not work?

 

P.S. https://support.smartbear.com/articles/testcomplete/embedding-scripts-into-web-pages/ might appear to be an inspiring reading...

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Community Manager

Re: The dispatchEvent browser method doesn't work

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. 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: The dispatchEvent browser method doesn't work

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.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors