Watir Tip of the Day – Javascript events

August 21, 2008

Ever right-click on a link and it shows javascript://? You won’t be able to do the usual link.click in Watir.

Solution: Use the fire_event call. Below is an example of clicking a link that executes a javascript command to open a new window.

$ie.link(:text, “Help”).fire_event(”onclick”)

$ie = Instance of Internet Explorer

Link has a text value of “Help”.

Fire the event on mouse click.

Another example:

ie.text_field(:name, "my_field").fire_event("onchange")

Previous post: Waterfall Process Model

Next post: Related links