Patched in support for hover, manual mouse move/up/down, simulated FF events.

48 views
Skip to first unread message

Robin Lee Powell

unread,
May 9, 2011, 3:32:47 PM5/9/11
to selenium-...@googlegroups.com

I really really needed manual mouse control in FF. I spent all
weekend on this. The events are simulated, not native, and I have
no idea what I'm doing so I'm sure I did it wrong, but it *works*; I
can now deal with jquery drags that require hover first.

Patches attached:

1. Mini-patch to "go" that was required to get it working on one of
my machines; otherwise it tried to allocate more RAM than the
machine had.

2. Added mousedown and mouseup events to dispatcher. Added support
for non-native mousemove, and new code for mousedown and mouseup

I explicitely release this code to the selenium and webdriver
committers to do whatever they want with, including claim it as
their own work, although I'd certainly prefer attribution.

Note that when I say "hover", I just mean mouse movement that
happens to activate mouseover and mouseout; I haven't tried to put
back the deprecated hover bits.

Example of how I'm using this, via the Ruby bindings:

e=@driver.find_element(:xpath, "//span[text()='IL-4']")
@driver.action.click_and_hold(e).perform;
@driver.action.move_to(e, 0, 10).perform;
@driver.action.move_to(e, 0, 10).perform;
@driver.action.release(e).perform;

My apologies if the code stinks, but I just needed something that
works, and I seriously spent 20+ hours on this over the weekend (I
had no previous experience with FF extensions) so I do request that
if it's awful you not be *too* mean about it :), and that even if
you don't use this code, that the next release have *some* way of
doing these things, because I really can't test without it.

-Robin

--
http://singinst.org/ : Our last, best hope for a fantastic future.
Lojban (http://www.lojban.org/): The language in which "this parrot
is dead" is "ti poi spitaki cu morsi", but "this sentence is false"
is "na nei". My personal page: http://www.digitalkingdom.org/rlp/

sel2_mini
sel2_main

Robin Lee Powell

unread,
May 9, 2011, 3:58:49 PM5/9/11
to Selenium Developers
On May 9, 12:32 pm, Robin Lee Powell <rlpow...@digitalkingdom.org>
wrote:
> I really really needed manual mouse control in FF.  I spent all
> weekend on this.  The events are simulated, not native, and I have
> no idea what I'm doing so I'm sure I did it wrong, but it *works*; I
> can now deal with jquery drags that require hover first.

I've just noticed that while IE (via RemoteDriver) happily accepts
mousedown via the same commands, it doesn't seem to actually work.
mouseover works, but only for about half a second, then it goes away
somehow.

Hopefully someone else can take a crack at the IE side of things.

I think that it's always possible to find situations where things like
dragElement don't do what you want; I think it's really important that
there be some way to get Selenium to emit exactly the javascript
events a test needs, manually, so I really hope the next 2.0 release
will cover this.

-Robin

Jari Bakken

unread,
May 9, 2011, 5:14:41 PM5/9/11
to selenium-...@googlegroups.com
On Mon, May 9, 2011 at 9:32 PM, Robin Lee Powell
<rlpo...@digitalkingdom.org> wrote:
> Example of how I'm using this, via the Ruby bindings:
>
>  e=@driver.find_element(:xpath, "//span[text()='IL-4']")
>  @driver.action.click_and_hold(e).perform;
>  @driver.action.move_to(e, 0, 10).perform;
>  @driver.action.move_to(e, 0, 10).perform;
>  @driver.action.release(e).perform;
>

Just a quick tip. The idea of the ActionBuilder is that you can chain
actions, so you only need to call perform() once:

https://gist.github.com/963429

(I wasn't sure why you were calling move_to twice, but you could
easily keep that without adding another perform() call.)

Robin Lee Powell

unread,
May 9, 2011, 5:59:59 PM5/9/11
to Selenium Developers
On May 9, 2:14 pm, Jari Bakken <jari.bak...@gmail.com> wrote:
> On Mon, May 9, 2011 at 9:32 PM, Robin Lee Powell
>
> <rlpow...@digitalkingdom.org> wrote:
> > Example of how I'm using this, via the Ruby bindings:
>
> >  e...@driver.find_element(:xpath, "//span[text()='IL-4']")
> >  @driver.action.click_and_hold(e).perform;
> >  @driver.action.move_to(e, 0, 10).perform;
> >  @driver.action.move_to(e, 0, 10).perform;
> >  @driver.action.release(e).perform;
>
> Just a quick tip. The idea of the ActionBuilder is that you can chain
> actions, so you only need to call perform() once:
>
>  https://gist.github.com/963429

Good stuff, thanks! I still have trouble with idiomatic Ruby. :)

> (I wasn't sure why you were calling move_to twice, but you could
> easily keep that without adding another perform() call.)

Emulating slow/human-ish movement. There's a speed control in
dragElement but (1) I can't see any way to change that setting at all
from the RemoteDriver and (2) it doesn't help me anyways as the things
I'm working with require a hover and then a down and then a move and
then an up.

-Robin

Eran M.

unread,
May 10, 2011, 6:44:24 AM5/10/11
to selenium-...@googlegroups.com
Thanks for the patch, Robin. I'll incorporate it as the fallback route in case native events are not supported. 
Note that emulation of mouse move via event firing never really worked (my suspicion is that the browser discards some events if it does not have focus).

Eran


--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To post to this group, send email to selenium-...@googlegroups.com.
To unsubscribe from this group, send email to selenium-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-developers?hl=en.


Robin Lee Powell

unread,
May 10, 2011, 1:04:05 PM5/10/11
to Selenium Developers
Glad it's going to get used! :) I would have been OK even if it was
just a hold-over until the next release, but I put enough work into it
that it's nice to know.

WRT emulation not working for you: Huh. It works perfectly in my
tests; I've got jQuery elements that need hover + drag floating around
the landside wonderfully. *shrug*

-Robin

Simon Stewart

unread,
May 16, 2011, 5:38:57 AM5/16/11
to selenium-...@googlegroups.com
Most browsers can detect when events have been synthesized and most
ignore them (cf: filling input fields with keydown/up on webkit)
Firefox does this with synthesized mouse move events.

Simon

Robin Lee Powell

unread,
May 24, 2011, 12:27:06 AM5/24/11
to Selenium Developers
As I said, it works perfectly for me; I have tests relying
*extensively* on this code.

-Robin
Reply all
Reply to author
Forward
0 new messages