我正试图用Selenium
、WebDriverJS
和Jasmine
创建一个测试,以验证无论何时使用拖放选择向右移动li
元素,都不应再显示它。这是我的代码片段:
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)
法中。你知道是什么导致了这个问题以及解决它的可能方法吗?提前感谢您的回复!
目前您也可以进行
.dragAndDrop(card1, { x: 100, y: 0 })
正是它做到了这一点——mouseDown(element).mouseMove(location).mouseUp()
请参阅此处
用mouseMove({x: offsetFromCenter, y: offsetFromCenter})
替换mouseMove(card1Move)
例如CCD_ 9将向卡片1的中心的右侧移动100px。
我在量角器中遇到了同样的错误"失败:location.getRawId不是函数"-我的问题是找不到我正在搜索的元素。