Usha Guduri

Advanced Watir Use

…if you want to call hacking Watir to work with certain “advanced” UI elements that!

Element in the works: jQuery UI’s Slider

There’s nothing straightforward in Watir to change the slider and trigger the events as if the user interacted with the slider. In a normal slider implementation, that would either be the ‘change’ or ‘stop’ events on the slider. So how do you do that? Use the execute_script to directly do what you need via javascript.

1
2
3
$slider = $(“#myslider);
$slider.slider(option, values, [min, max]); //automatically triggers the ‘change’ event
$slider.call($slider, stop, event, ui)

event and ui are objects you can self-create and send to the caller since your call handler signature would’ve been

1
2
3
stop: function(event, ui) {
...
}

Now that you know the js, you can simply execute it on the watir’s ‘browser’ instance

Solution:

1
browser.execute_script <all the above js>

Lesson: Watir can be hacked to work even with complex and dynamic web pages ;-)

Comments