I have some code that I wrote about 3 years ago that does this. Ive
put it here, but Im not sure it would be much use as it is because of
the version of watir it was written against, and looking through it
appears to be IE only. Im afraid I dont have time to help out with it,
but if you can make something useful out of it, please do.
Hope it helps,
Paul
class EventInfo
# see http://msdn2.microsoft.com/en-us/library/ms533544(VS.85).aspx
LEFT_MOUSE = 1
RIGHT_MOUSE = 2
NO_MOUSE = 0
attr_accessor :clientX
attr_accessor :clientY
attr_accessor :screenX
attr_accessor :screenY
attr_accessor :x
attr_accessor :y
attr_accessor :expando
attr_accessor :ctrl_key
attr_accessor :shift_key
attr_accessor :alt_key
attr_accessor :mouse_button
attr_accessor :key_code
# these 2 are used to supply the id tags for events that start on
different objects
# ie we may fire the event on the document object, but we want
tthe src and target objects to be, for example divs
attr_accessor :target_element_id
attr_accessor :src_element_id
end
class Element
# Executes a user defined "fireEvent" for objects with JavaScript
events tied to them such as DHTML menus.
# usage: allows a generic way to fire javascript events on page
objects such as "onMouseOver", "onClick", etc.
# raises: UnknownObjectException if the object is not found
# ObjectDisabledException if the object is currently disabled
def fire_event(event , extra_info=nil )
#assert_enabled
#highlight(:set)
temp_id = nil
if extra_info
if self.id.nil? or self.id==""
temp_id = "WatirTempID_" + Time.now.to_i.to_s
self.ole_object["id"]=temp_id
end
fire_event_with_extras( event , extra_info )
else
self.locate
self.ole_object.fireEvent(event)
end
@container.wait
#highlight(:clear)
end
def fire_event_with_extras( event , extra_info )
raise "Cant use event info unless target elment has an id" if
self.id.nil? or self.id==""
src_element_string = "target"
src_element_string =
"document.getElementById('#{extra_info.src_element_id}')" if
extra_info.src_element_id
#puts "src_element_string = "
#puts src_element_string
#puts "--"
js=<<-end_js
e=document.createEventObject()
// these seem to be ignored, and clientX and clientY
values get used in their place
e.x =#{extra_info.x || 0};
e.y=#{extra_info.y || 0};
e.clientX = #{extra_info.clientX || 0 };
e.clientY = #{extra_info.clientY || 0 };
e.screenX = #{extra_info.screenX || 0 };
e.screenY = #{extra_info.screenY || 0 };
e.expando="#{extra_info.expando}";
e.ctrlKey=#{extra_info.ctrl_key || false };
e.altKey=#{extra_info.alt_key || false };
e.shiftKey=#{extra_info.shift_key || false};
e.button=#{extra_info.mouse_button || 0 };
e.keyCode=#{extra_info.key_code || 0 };
target= document.getElementById('#{self.id}');
e.srcElement = target;
e.fromElement = target;
e.toElement = target;
//e.relatedTarget = target;
e.target = target;
//alert( "before: " + e.clientX + " " + e.clientY + " "
+ e.srcElement + " " + e.fromElement + " " + e.toElement );
target.fireEvent('#{event}' , e );
//alert( "after: " + e.relatedTarget + e.clientX + " " +
e.clientY + " " + e.srcElement + " " + e.fromElement + " " +
e.toElement );
end_js
#puts js
ole_object.ownerDocument.parentWindow.execScript( js )
end
private :fire_event_with_extras
end
On Thu, May 26, 2011 at 1:44 AM, Chuck van der Linden <[email protected]> wrote:
> I'd wager it's working off keypress events. Problem is we can't
> easily fire those in watir because the .fire_event method only takes a
> single parameter (the event) and I believe to work properly keypress
> needs a parameter for the value of the key that was depressed.
>
> You might need to write your own function that executes the javascript
> fireevent function instead, similar to this item from Stackoverflow a
> year or two ago
> http://stackoverflow.com/questions/602069/autocomplete-dropdown-test-with-ruby-watir
>
> Another alternative is described here
> http://zbarzone.blogspot.com/2008/08/watir-sendkeys-and-javascript.html
> and that approach might actually be better for you.
>
> To fix this 'for real' it seems we'd need to first modify .fire_event
> to allow for a second parameter, or create a new method such
> as .fire_key_event that would take two parameters. Then any other
> methods that have keypress events in them such as .set would need to
> be altered to fire the down/press/up events character by character and
> fire those events with the proper 'key' values for each character.
>
> On May 24, 11:24 am, Lisa Crispin <[email protected]> wrote:
>> I tried the log events thing, it's nice to know about that, but I don't see
>> anything that really looks like the JS firing. I see a lot of 'select',
>> 'click' 'keydown', 'input', 'keypress', 'keyup', none of that looks like
>> what the JS is doing with the type ahead.
>> -- LIsa
>>
>> On Mon, May 23, 2011 at 2:36 PM, Željko Filipin <
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> [email protected]> wrote:
>> > On Mon, May 23, 2011 at 9:44 PM, Lisa Crispin <[email protected]>
>> > wrote:
>> > > We are changing what used to be regular drop-down select list boxes to a
>> > dojo widget thingie that allows type ahead to select the item.
>>
>> > Is the page public? Or a similar page? Frameworks usually have examples
>> > somewhere online.
>>
>> > If you think the only problem is that a JavaScript event is not fired (by
>> > Watir), take a look at this:
>>
>> >http://stackoverflow.com/questions/3787555/how-to-find-out-which-java...
>>
>> > If the site is not public, but you could show it to me, contact me off
>> > list.
>>
>> > Željko
>> > --
>> > watir.com - community manager
>> > watir.com/book - author
>> > watirpodcast.com - host
>> > viaqa.mobi conference on software testing - organizer
>>
>> > --
>> > Before posting, please readhttp://watir.com/support. In short: search
>> > before you ask, be nice.
>>
>> > [email protected]
>> >http://groups.google.com/group/watir-general
>> > [email protected]
>>
>> --
>> Lisa Crispin
>> Co-author with Janet Gregory, _Agile Testing: A Practical Guide for Testers
>> and Agile Teams_ (Addison-Wesley 2009)
>> Contributor to _Beautiful Testing_ (O'Reilly 2009)http://lisacrispin.com
>> @lisacrispin on Twitterhttp://entaggle.com/lisacrispin
>
> --
> Before posting, please read http://watir.com/support. In short: search before
> you ask, be nice.
>
> [email protected]
> http://groups.google.com/group/watir-general
> [email protected]
>
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]