d_z90 d_z90 - 5 months ago 109
Javascript Question

Drag-and-drop element to specific position - Selenium, WebDriverJS

I am trying to create a test with

Selenium
,
WebDriverJS
and
Jasmine
to verify that whenever a
li
element is moved right with a drag-and-drop selection, it should not be displayed anymore. This is the snippet of my code:

it('should make the card disappear when the UI is swiped right', function() {
var card1 = driver.findElement(webdriver.By.css('.slide:nth-last-child(1)'));
var card1Move = driver.executeScript('arguments[0].setAttribute("style", "right:250px")', card1);
driver.actions()
.mouseMove(card1)
.mouseDown()
.mouseMove(card1Move)
.mouseUp()
.perform();
driver.findElement(webdriver.By.css('.slide:nth-last-child(1)')).isDisplayed()
.then(function(elem) {
expect(elem).toBe(false);
});
})


The function appear to be working, but I get the following error:

Failures:
1) Swiping method should make the card disappear when the UI is swiped right

Message:
TypeError: location.getRawId is not a function
Stack:
TypeError: location.getRawId is not a function
at webdriver.ActionSequence.mouseMove (/Users/.../node_modules/selenium-webdriver/lib/webdriver/actionsequence.js:108:46)
at Object.<anonymous> (/Users/.../tests/index.js:27:14)


According to the test, the error is in the
.mouseMove(card1Move)
method.
Do you know what is causing this issue and a possible way to solve it? Thanks in advance for your replies!

Answer

Replace mouseMove(card1Move) with mouseMove({x: offsetFromCenter, y: offsetFromCenter})

e.g. mouseMove({x: 100, y: 0}) will move 100px to the right of card1's center.