How to find out which JavaScript events fired?

0 votes
asked Sep 24, 2010 by %c5%bdeljko-filipin

I have a select list:

<select id="filter">
  <option value="Open" selected="selected">Open</option>
  <option value="Closed">Closed</option>

When I select Closed the page reloads. In this case it shows closed tickets (instead of opened). It works fine when I do it manually.

The problem is that the page does not reload when I select Closed with Watir:

browser.select_list(:id => "filter").select "Closed"

That usually means that some JavaScript event is not fired. I can fire events with Watir:

browser.select_list(:id => "filter").fire_event "onclick"

but I need to know which event to fire.

Is there a way to find out which events are defined for an element?

2 Answers

0 votes
answered Sep 5, 2011 by chris

Just thought I'd add that you can do this in Chrome as well:

Ctrl + Shift + I (Developer Tools) > Sources> Event Listener Breakpoints (on the right).

You can also view all events that have already been attached by simply right clicking on the element and then browsing its properties (the panel on the right).

For example:

Right click on the upvote button to the left Select inspect element Collapse the styles section (section on the far right - double chevron) Expand the event listeners option Now you can see the events bound to the upvote

Not sure if it's quite as powerful as the firebug option, but has been enough for most of my stuff.

Another option that is a bit different but surprisingly awesome is Visual Event:

It highlights all of the elements on a page that have been bound and has popovers showing the functions that are called. Pretty nifty for a bookmark! There's a Chrome plugin as well if that's more your thing - not sure about other browsers.

AnonymousAndrew has also pointed out monitorEvents(window); here

0 votes
answered Sep 5, 2013 by anonymousandrew

Regarding Chrome, checkout the monitorEvents() via the command line API.

  • Open the console via Menu > Tools > JavaScript Console.
  • Enter monitorEvents(window);
  • View the console flooded with events

    mousemove MouseEvent {dataTransfer: ...}
    mouseout MouseEvent {dataTransfer: ...}
    mouseover MouseEvent {dataTransfer: ...}
    change Event {clipboardData: ...}

There are other examples in the documentation. I'm guessing this feature was added after the previous answer.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter