Dashboard > Watir > ... > Advanced Examples > Possibilities For New Events in Watir
Watir Log In View a printable version of the current page.
Possibilities For New Events in Watir
Added by Paul Rogers, last edited by Alister Scott on Sep 29, 2008  (view change)
Labels: 
(None)

Some web sites use DOM events. See http://msdn2.microsoft.com/en-us/library/ms536913(VS.85).aspx or http://msdn2.microsoft.com/en-us/library/ms536938(VS.85).aspx

Watr does not currently fill in the DOM event object ( http://msdn2.microsoft.com/en-us/library/ms535863(VS.85).aspx ) which means that a web page that has the following html will not work correctly when accessed via watir.

<html><head><title>Events Page</title>
<script>
function updateEventInfo(){
   xbox = document.getElementById('x');
   ybox = document.getElementById('y');

   ev = window.event;
   xbox.value = ev.x;
   ybox.value = ev.y;
}
</script>
</head>
<body>

  <div id='evtester' onClick='updateEventInfo()' style='height:100;width:200' >Click On Me</div>
  x:<input type = text id = x><br>
  y:<input type = text id =y >
</body>
</html>

Using the code shown at the end, watir would be able to access these types of pages. This code does have some limitations- curently the html element that youy wish to access must have an ID set.

This similar code could be used on text fields that detect which key has been pressed ( a technique often used on text areas to limit the number of chars that can be entered)

The implementation on this really comes in 2 parts. The first part is to allow fire_event to take an event object as an optional second parameter.
The second would be to allow the click method to take an optional second parameter, which would be the event data. The set method for text fields would also be modified to always use the correct event info, so that text areas as described above would work with out any additional work.

Ive also done a similar thing for Firewatir, but I need to fix the api to be the same for both.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators