Search code examples
javascripteventswatirdom-eventsbrowser-automation

How to find out which JavaScript events fired?


I have a select list:

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

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?


Solution

  • Looks like Firebug (Firefox add-on) has the answer:

    • open Firebug
    • right click the element in HTML tab
    • click Log Events
    • enable Console tab
    • click Persist in Console tab (otherwise Console tab will clear after the page is reloaded)
    • select Closed (manually)
    • there will be something like this in Console tab:

      ...
      mousemove clientX=1097, clientY=292
      popupshowing
      mousedown clientX=1097, clientY=292
      focus
      mouseup clientX=1097, clientY=292
      click clientX=1097, clientY=292
      mousemove clientX=1096, clientY=293
      ...
      

    Source: Firebug Tip: Log Events