wmmhihaa
wmmhihaa

Reputation: 953

Selenium: driver.actions(...).moveToElement is not a function

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.com/")
    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"
  }

Upvotes: 3

Views: 5448

Answers (2)

3learner
3learner

Reputation: 27

Below is a comparison 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();

Upvotes: 2

Michał Stachowski
Michał Stachowski

Reputation: 21

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

Upvotes: 2

Related Questions