Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the mouse to an arbitrary point using Protractor/Selenium

Tags:

Is it possible to move the mouse to arbitrary coordinates on the screen/relative to an element in Protractor tests? I see people recommend using Robot for Java users, but of course I can't use that in JavaScript.

like image 282
Andy Avatar asked Feb 24 '15 20:02

Andy


People also ask

Which are the mouse actions in protractor?

Drag and Drop Mouse Actions In Selenium Protractor The dragAndDrop() action of the mouse event drags the source element to the target element via mouse actions in Selenium Protractor. After this, you can perform any other operation, as per your requirement.

How do you mouse hover and click in protractor?

How do you do a hover action on a protractor? mouseMove / hover in protractor With the object of the action, you should first move to the menu element, and then move to the submenu item and click it or perform whatever action you wish.


1 Answers

I figured it out for myself...just took some deep digging through Protractor and Selenium documentation. Here is some example code:

  it('should pan plots when you click and drag', function() {     var plot0 = element(by.css('.plot > canvas'));     browser.actions()       .mouseMove(plot0, {x: 100, y: 100}) // 100px from left, 100 px from top of plot0       .mouseDown()       .mouseMove({x: 400, y: 0}) // 400px to the right of current location       .perform();   }); 
like image 179
Andy Avatar answered Oct 09 '22 19:10

Andy