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

javascript - Selenium: driver.actions(...).moveToElement is not a function - Stack Overflow

programmeradmin1浏览0评论

Hi I've created all my tests using Selenium IDE and have now started to export them to JavaScript Mocha to have them running in travis.

The tests run fine in selenium ide and I can export them, but when I run it it says "TypeError: driver.actions(...).moveToElement is not a function".

 it('Console Page should work', async function() {
    await driver.get("/")
    await driver.manage().window().setRect(1536, 824)
    await driver.findElement(By.id("loginLink")).click()
    {
      const element = await driver.findElement(By.id("Password"))
      await driver.actions({ bridge: true }).moveToElement(element).clickAndHold().perform() // this line fails
    }

package dependancies:

"dependencies": {
    "chai": "^4.2.0",
    "mocha": "^7.1.2",
    "chromedriver": "^81.0.4044.138",
    "selenium-webdriver": "^4.0.0-alpha.7"
  }

Hi I've created all my tests using Selenium IDE and have now started to export them to JavaScript Mocha to have them running in travis.

The tests run fine in selenium ide and I can export them, but when I run it it says "TypeError: driver.actions(...).moveToElement is not a function".

 it('Console Page should work', async function() {
    await driver.get("https://myurl./")
    await driver.manage().window().setRect(1536, 824)
    await driver.findElement(By.id("loginLink")).click()
    {
      const element = await driver.findElement(By.id("Password"))
      await driver.actions({ bridge: true }).moveToElement(element).clickAndHold().perform() // this line fails
    }

package dependancies:

"dependencies": {
    "chai": "^4.2.0",
    "mocha": "^7.1.2",
    "chromedriver": "^81.0.4044.138",
    "selenium-webdriver": "^4.0.0-alpha.7"
  }
Share Improve this question asked May 14, 2020 at 10:41 wmmhihaawmmhihaa 9532 gold badges9 silver badges30 bronze badges 1
  • Same error. Were you able to fix it? – Chirag Arora Commented Jun 15, 2020 at 20:36
Add a ment  | 

2 Answers 2

Reset to default 2

change this

await driver.actions({bridge:true}).moveToElement(element).clickAndHold().perform()

To

await driver.actions({ bridge:true}).move(element).clickAndHold().perform()

It's change from new versions

Below is a parison between how it is working in Python, Java and JavaScript:

Python:

# Performs mouse move action onto the element
webdriver.ActionChains(driver).move_to_element(yourElement).perform()

Java:

Actions actions = new Actions(driver);
// Performs mouse move action onto the element
actions.moveToElement(yourElement).build().perform();

JavaScript:

const actions = await driver.actions({bridge: true});
// Performs mouse move action onto the element
await actions.move({duration: 1000, origin:yourElement, x: 1, y: 1}).perform();
发布评论

评论列表(0)

  1. 暂无评论