How I learned to love Selenium’s fireEvent

"I clicked on that, why didn't the click work!"

I recently faced the challenge of using Selenium to automate a web application that stubbornly resisted my attempts to automate it - until I found the fireEvent!

No need to know the name of the application in question, but the basic situation I faced involved a form with a 'save' button.

I used Selenium to fill in the details in the form and click the save button.

When I run selenium I can see the text I enter on the form, and when the 'save' gets a click the little Ajax image for 'saving' appears, but when I check the data saved - nothing got saved.

I struggled with this on my own for a while then paired with someone to help.

Pairing brings a number of benefits:

  • 2 minds instead of one
  • you engage in the 'ah!' moments that only happen when you explain something to others
  • you get a fresh perspective on the problem

So instead of focusing on the 'save' event we had a look at the form input fields.

The input fields had a few events - one having an onblur event. The onblur event code seemed to suggest that it persisted the form data into an in-memory store which the 'save' event then processed. So the problem did not seem to involve the save event - the type command did not trigger an onblur when it 'moved' between fields.

Onblur fires when you lose focus so we first tried clicking on the other fields to make that happen.

But that didn't work.

And then we noticed the Selenium API command fireEvent. This lets you trigger the event for a particular element on a page so we simply fired the 'blur' event for the component 


selSession.fireEvent("edit_field_1", "blur");

And that worked - deep joy.

So lessons learned for me:

  • Selenium has a large API - which I need to spend more time learning the scope and extent of
  • When testing I need to use the Firefox/Firebug 'inspect element' functionality to learn a bit more about the app under test
  • I need to use fireEvent more instead of some of the fudges present in my existing tests - this might help make them more robust.

General lessons:

  • Any testing you do, learn the technology that underpins it
  • Work with developers and use their technical knowledge to help

6 Responses to “How I learned to love Selenium’s fireEvent”

  1. […] Selenium: fireEvent() помогает в работе с элементами […]

  2. Thanks for this tip! I too need to learn the Selenium api.
    thanks again

  3. seleniumbeginner on August 20th, 2009 at 11:57 pm

    This is a great piece of information..Thank you so much! I have been stuck with this problem for more than a day…and today is the day when i started loving selenium’s fireEvent :)

  4. Thanks for your post!
    fireEvent (blur) made my day!

  5. I think I love you. Been pulling my hair out on this one. Thank you thank you thank you!

  6. Thank you so much for this post! I was trying to test an ajax autocomplete input field that’s triggered by the keyup event. I tried ‘type’, ‘keyup’, ‘keypress’, ‘keydown’ and combinations of all of those without any luck. I didn’t realize that selenium did input without triggering events. I definitely agree that selenium has a large API, and it would take some time to learn to use it effectively. I just wish the docs and community support for it wasn’t so crappy.

Leave a Reply