protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Dragging mouse on the screen

Open aarkanov opened this issue 12 years ago • 6 comments

Hi,

Not sure if anyone has encountered this issue, but I have a webapp where I need to swipe between screens (i.e drag the mouse from one side to another).

I've tried using:

   browser.actions().mouseMove({x:0, y:300}).mouseMove({x:200, y:300}).perform();

but that doesn't seem to do anything, and I don't get any errors. Does anyone have any suggestions?

Any help would be appreciated.

aarkanov avatar Aug 14 '14 13:08 aarkanov

Hi

if you want to 'drag' - that is typically (MouseMove->)MouseDown->MouseMove->MouseUp. Try adding mouseUp and mouseDown. Have a look here for Actions API: https://code.google.com/p/selenium/source/browse/javascript/webdriver/actionsequence.js

zakrhol avatar Aug 15 '14 07:08 zakrhol

The only thing is i want to move it left and right, thus the coordinates. Any suggestions for that?

aarkanov avatar Aug 15 '14 14:08 aarkanov

I've also tried the following:

browser.actions().mouseDown().mouseMove({x:300, y:200}).mouseMove({x:0, y:200}).mouseUp().perform().then(function() {
          var text = element(by.tagName('html')).getText();
          expect(text).toContain('Buying');  
        });

and that doesn't seem to work either.

aarkanov avatar Aug 18 '14 15:08 aarkanov

Drag + drop is hard to work with - collecting these issues under master #1205

juliemr avatar Aug 18 '14 21:08 juliemr

var plot0 = ptor.element(protractor.By.id('')); ptor.driver.actions() .dragAndDrop(plot0, {x: 100, y: 100}) .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();

dhinakarankannan avatar Mar 21 '17 16:03 dhinakarankannan

I figured out how to draw a rectangular loop on the screen with simulated mouse down, drags, and mouse up:


browser.driver.actions()
      .mouseDown(graphElement)
      .mouseMove({ x: 200, y: 0 })
      .mouseMove({ x: 0, y: 200 })
      .mouseMove({ x: -200, y: 0 })
      .mouseMove({ x: 0, y: -200 })
      .mouseMove({ x: 200, y: 0 })
      .mouseUp()
      .perform();

(see API)

maiasmith avatar Dec 08 '17 19:12 maiasmith