Category: watir

Execute Javascript from Watir

To execute javascript from a Watir script you can use the following trick.

ie.document.parentWindow.execScript("window.open('#{url}', 'NAME')")

This particular script was usefull to simulate a popup window from a parent browser window. Opening a new window from Watir directly with

IE.new_process()

creates a second browser window that is “not trusted” from the originating browser window.

Also make sure that the web application is from a trusted “local intranet” site in IE, otherwise you get security violation errors.

Using IE Developer Toolbar with popups

The Ruby Watir library makes it possible to automatically click through web apps. This is useful for automated integration or functional testing.

The IE Developer Toolbar makes it easy to view the DOM structure of the pages to automatically test and find all the ids and names of the links and buttons to click.

To activate the developer toolbar you click on the IE Developer Toolbar button on top of the browser menu bar. With popup screens without a menu bar, this is not possible.

Te solution I use here is to click ‘F11′ in the IE popup window, which expands it to full screen. Now the IE Developer Toolbar is clickable! Now you can find the ids of the HTML widgets in the popup.