Reputation: 1856
I need to automate interaction with a custom jQuery rich text editor in our web client. Having talked with our developers I would only need to be able to fire the following events; keydown, keyup, mousedown, mouseup and paste.
So really need a way of being able to pass a key code with the fire_event keydown and keyup calls for WATIR and FIREWATIR?
Has anyone had any success in doing this?
Upvotes: 2
Views: 2443
Reputation: 6660
Have you tried the send_keys method? I know watir-webdriver supports it, and it seems that is rapidly becoming the preferred way of driving firefox
Upvotes: 2
Reputation: 5880
i had a similar need a long time ago. I believe, your best bet is
@browser.document.parentWindow.eval(‘javascript’)
I've just tried the following on some page with included jquery:
$('body').keydown(function(e) {alert(e.keyCode)}); // Assign keydown event to 'body', so it will alert with the key code of any button pressed
var event = jQuery.Event("keydown");
event.keyCode = 50; // Whatever keyCode you need
jQuery("body").trigger(event); // Here you replace 'body' with the element you need
so, basically, you craft an event and trigger it on any element you need
the whole picture might look something like:
@browser.document.parentWindow.eval('var event = jQuery.Event("keydown"); event.keyCode = 50; jQuery("#theElementYouNeed").trigger(event)')
Upvotes: 1