最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Drag-and-drop element to specific position - Selenium, WebDriverJS - Stack Overflow

programmeradmin0浏览0评论

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!

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!

Share Improve this question edited Nov 18, 2015 at 15:37 d_z90 asked Nov 18, 2015 at 15:28 d_z90d_z90 1,2632 gold badges20 silver badges49 bronze badges 2
  • Is it reproduced in different browsers? Could you also post the plete error traceback? Thanks. – alecxe Commented Nov 18, 2015 at 15:32
  • Just in Firefox. Sure! I have just updated it for you. – d_z90 Commented Nov 18, 2015 at 15:38
Add a ment  | 

3 Answers 3

Reset to default 2

Currently you can also do

.dragAndDrop(card1, { x: 100, y: 0 })

which does exactly this - mouseDown(element).mouseMove(location).mouseUp()

see here

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.

I had the same error in protractor "Failed: location.getRawId is not a function" - my issue was that the element I was searching was not to be found.

发布评论

评论列表(0)

  1. 暂无评论