My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit http://samueladesoga.wordpress.com and update your bookmarks.

Thursday 6 November 2008

Selenium and Javascript events

Have you ver been in situattion when youhave typed a value into a text box and you expect a
Javascript event to be called such as "OnBlur"

welll selenium has a method "FireEvent" which triggers the event for you, but then the trick is you have to strip the "on" and name for the event wouldbe "OnBlur"

I guess abit of example would make more sense, lol.
This is what my html look like

<input type="text" value="" onblur="JavaScript:ValidateSimpleMail(true);" size="25" name="EMAIL_1" id="EMAIL_1"/>

selenium command to type into an email box, which doesnt fire the event attached to the text box

browser.Type("EMAIL_1", "sam@sam.com");

The work around is to use selenium to fire the event after it has typed in the textbox
FireEvent(locator, eventName) which in my case is

browser.FireEvent("EMAIL_1", "blur");

1 comment:

Srimathi Mani said...

That was great...Got the solution for my problem..Thanks