将元素拖放到特定位置 - Selenium、WebDriverJS

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

我正在尝试使用 SeleniumWebDriverJSJasmine 创建一个测试,以验证每当 li 元素用 [=23= 向右移动时]拖放选择,它不应该再显示了。这是我的代码片段:

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);
        });
})

函数似乎可以正常工作,但出现以下错误:

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)

根据测试,错误在.mouseMove(card1Move)方法中。 你知道是什么导致了这个问题以及解决它的可能方法吗?预先感谢您的回复!

mouseMove(card1Move)替换为mouseMove({x: offsetFromCenter, y: offsetFromCenter})

例如mouseMove({x: 100, y: 0}) 将向 card1 中心右侧移动 100px。

目前您还可以

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

正是这样做的 - mouseDown(element).mouseMove(location).mouseUp()

here

我在量角器中遇到了同样的错误 "Failed: location.getRawId is not a function" - 我的问题是找不到我正在搜索的元素。