How to simulate (trigger) mouse move event using jQuery in Robot Framework

2,967 views
Skip to first unread message

Martyna Petrosiute

unread,
Mar 20, 2012, 2:13:40 PM3/20/12
to robotframework-users
Hello,
after inefficient using drag and drop keyword and after investigation,
which events the system expects, I decided try to use "Execute
javascript" keyword for these events:
mousedown;
mousemove;
mouseup.
I use the code pasted bellow and in the log I can see, all these 3
keywords have passed successful, but it have not happened any movement
of my element. Element id = 'i#li1.list1' (jQuery); current element
position - { ${yposition}, ${xposition} }. Desirable element's
position - 250 pixels to the left - { ${yposition}, ${xposition} -
250 }.
The code, which does not work for me:

Execute javascript
jquery=this.browserbot.getUserWindow().jQuery('i#li1.list1').mousedown;
Execute javascript
jquery=this.browserbot.getUserWindow().jQuery('i#li1.list1').trigger(this.browserbot.getUserWindow().jQuery('i#li1.list1').mousemove,
{clientY: ${yposition}, clientX: ${xposition}-250});
Execute javascript
jquery=this.browserbot.getUserWindow().jQuery('i#li1.list1').mouseup;

As I mentioned, this code does not gives any exceptions, errors, it
passes, but doesn't move element.
I really appreciate any help. Thanks.

Daniel Aquino

unread,
Mar 20, 2012, 6:26:05 PM3/20/12
to martyna.p...@accedo.tv, robotframework-users
I posted a response for this problem into the selenium library mailing
list but I'll put it here too..

It's because jquery is running in the controller window not the client
window.. (note that jquery remembers which window it was started in
and it has ability to navigate any dom you pass to it which is what
jquery= selector in fact does)..

You can try something like the following just remember here that
${code} can't contain single quotes in this example..

Execute Javascript From App
[Arguments] ${code}
[Documentation] Runs the given javascript from inside the
application window instead of from the selenium controller window like
the original Execute Javascript does.
Execute Javascript window.eval('${code}')

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

Martyna Petrosiute

unread,
Mar 21, 2012, 7:47:56 AM3/21/12
to robotframework-users
Thank you, Daniel, for response. I think, that my jquery is running in
the right window, because other keywords executing with jquery like
click(), mousedown() and mouseup() were executed successfully (I've
checked with several elements). Maybe my "mousemove" syntax is not
correct. I wonder, if it is possible to simulate mousemoving using
jquery at all, because, as I understand, mousemove() event works then,
when user moves the mouse. I tried to use trigger and bind events with
mousemove, but I did not succeed.

Martyna Petrosiute

unread,
Mar 21, 2012, 1:00:59 PM3/21/12
to robotframework-users
I found a simple java method for mouse pointer moving - mousemove(int
x, int y), it should be used in the "robot" class and "java.awt"
package. Also I clarified, that it is possible to use java classes and
methods with robot framework. But as I understood the only way to use
java code is to import java library and create own defined keywords.
Maybe it is some more simple ways for using java code in robot
framework?

On Mar 21, 12:47 pm, Martyna Petrosiute <martyna.petrosi...@accedo.tv>
wrote:
> Thank you, Daniel, for response. I think, that my jquery is running in
> the right window, because other keywords executing with jquery like
> click(), mousedown() and mouseup() were executed successfully (I've
> checked with several elements). Maybe my "mousemove" syntax is not
> correct. I wonder, if it is possible tosimulatemousemoving using

Pekka Klärck

unread,
Mar 21, 2012, 6:00:30 PM3/21/12
to martyna.p...@accedo.tv, robotframework-users
2012/3/21 Martyna Petrosiute <martyna.p...@accedo.tv>:

> I found a simple java method for mouse pointer moving - mousemove(int
> x, int y), it should be used in the "robot" class and "java.awt"
> package.

This approach only works if you are testing a Swing application. Even
then the APIs provided by java.awt.robot are pretty low level and you
would be better off using higher level tools build on top of it.

> Also I clarified, that it is possible to use java classes and
> methods with robot framework. But as I understood the only way to use
> java code is to import java library and create own defined keywords.
> Maybe it is some more simple ways for using java code in robot
> framework?

The main requirement is that you need to run Robot on Jython or use
the remote library interface. The library itself can be written using
Java or Jython.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Reply all
Reply to author
Forward
0 new messages