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

Hi I've created all my tests using Selenium IDE and have now started to export them to JavaScript

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745298521a4621290.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信