nightwatch: moveToElement does not work on Safari or Firefox

Describe the bug

Calling moveToElement() works on Chrome, but does not work with Firefox or Safari.

Sample test

sampleTest.js

// Please add the sample test here

module.exports = {
  foo: function (browser) {
    browser.url("https://www.google.com");
    const gSearch =
      "#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b";

    browser.expect.element(gSearch).to.be.visible;
    browser.moveToElement(gSearch, 10, 10);

    browser.end();
  },
};

Run with command

$ nightwatch test/sampleTest.js -e firefox

$ nightwatch test/sampleTest.js -e safari

Verbose output

FIREFOX.debug.log

-------------FIREFOX----------------------------------
[Check Commands] Test Suite
===========================
ℹ Connected to localhost on port 4444 (2451ms).
  Using: firefox (79.0) on mac 18.5.0 platform.

Running:  foo

✔ Expected element <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b> to be visible (57ms)
 Error while running .moveTo() protocol action: An unknown error has occurred.


FAILED: 1 errors and  1 passed (3.844s)
_________________________________________________

TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (6.503s)

 ✖ checkCommands
 – foo (3.844s)

  TimeoutError: An error occurred while running .moveToElement() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: 
   {"status":-1,"value":"HTTP method not allowed","errorStatus":-1,"error":"An unknown error has occurred.","httpStatusCode":405}
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

SAFARI.debug.log

[Check Commands] Test Suite
===========================
ℹ Connected to localhost on port 4445 (20619ms).
  Using: Safari (12.1) on macOS platform.

Running:  foo

 Error while running .isElementDisplayed() protocol action: The command 'GET /session/5231F8CB-7429-43FD-AF4F-ECB106258372/element/node-D744DBF2-0D09-4AB9-BD96-57F89F7D5CE2/displayed' was not found.

✔ Expected element <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b> to be visible (26ms)
 Error while running .moveTo() protocol action: The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.


FAILED: 1 errors and  1 passed (536ms)
_________________________________________________

TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (21.759s)

 ✖ checkCommands
 – foo (536ms)

  TimeoutError: An error occurred while running .moveToElement() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.
   {"status":-1,"value":{"error":"unknown command","message":"The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.","stacktrace":""},"errorStatus":"","error":"The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.","httpStatusCode":404}
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

Configuration

nightwatch.json

// Autogenerated by Nightwatch
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
const Services = {};
loadServices();

module.exports = {
  // An array of folders (excluding subfolders) where your tests are located;
  // if this is not specified, the test source must be passed as the second argument to the test runner.
  src_folders: ["./tests"],

  // See https://nightwatchjs.org/guide/working-with-page-objects/
  page_objects_path: "",

  // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
  custom_commands_path: "",

  // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
  custom_assertions_path: "",

  // See https://nightwatchjs.org/guide/#external-globals
  globals_path: "",

  webdriver: {},

  test_settings: {
    default: {
      disable_error_log: false,
      launch_url: "https://nightwatchjs.org",

      screenshots: {
        enabled: false,
        path: "screens",
        on_failure: true,
      },

      desiredCapabilities: {
        browserName: "firefox",
      },

      webdriver: {
        start_process: true,
        server_path: Services.geckodriver ? Services.geckodriver.path : "",
      },
    },

    safari: {
      desiredCapabilities: {
        browserName: "safari",
        alwaysMatch: {
          acceptInsecureCerts: false,
        },
      },
      webdriver: {
        port: 4445,
        start_process: true,
        server_path: "/usr/bin/safaridriver",
      },
    },

    firefox: {
      desiredCapabilities: {
        browserName: "firefox",
        alwaysMatch: {
          // Enable this if you encounter unexpected SSL certificate errors in Firefox
          // acceptInsecureCerts: true,
          "moz:firefoxOptions": {
            args: [
              // '-headless',
              // '-verbose'
            ],
          },
        },
      },
      webdriver: {
        start_process: true,
        port: 4444,
        server_path: Services.geckodriver ? Services.geckodriver.path : "",
        cli_args: [
          // very verbose geckodriver logs
          // '-vv'
        ],
      },
    },

    chrome: {
      desiredCapabilities: {
        browserName: "chrome",
        chromeOptions: {
          // This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
          // w3c: false,
          // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
          args: [
            //'--no-sandbox',
            //'--ignore-certificate-errors',
            //'--allow-insecure-localhost',
            //'--headless'
          ],
        },
      },

      webdriver: {
        start_process: true,
        port: 9515,
        server_path: Services.chromedriver ? Services.chromedriver.path : "",
        cli_args: [
          // --verbose
        ],
      },
    },

    //////////////////////////////////////////////////////////////////////////////////
    // Configuration for when using the browserstack.com cloud service               |
    //                                                                               |
    // Please set the username and access key by setting the environment variables:  |
    // - BROWSERSTACK_USER                                                           |
    // - BROWSERSTACK_KEY                                                            |
    // .env files are supported                                                      |
    //////////////////////////////////////////////////////////////////////////////////
    browserstack: {
      selenium: {
        host: "hub-cloud.browserstack.com",
        port: 443,
      },
      // More info on configuring capabilities can be found on:
      // https://www.browserstack.com/automate/capabilities?tag=selenium-4
      desiredCapabilities: {
        "bstack:options": {
          local: "false",
          userName: "${BROWSERSTACK_USER}",
          accessKey: "${BROWSERSTACK_KEY}",
        },
      },

      disable_error_log: true,
      webdriver: {
        keep_alive: true,
        start_process: false,
      },
    },

    "browserstack.chrome": {
      extends: "browserstack",
      desiredCapabilities: {
        browserName: "chrome",
        chromeOptions: {
          // This tells Chromedriver to run using the legacy JSONWire protocol
          // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
          w3c: false,
        },
      },
    },

    "browserstack.firefox": {
      extends: "browserstack",
      desiredCapabilities: {
        browserName: "firefox",
      },
    },

    "browserstack.ie": {
      extends: "browserstack",
      desiredCapabilities: {
        browserName: "IE",
        browserVersion: "11.0",
        "bstack:options": {
          os: "Windows",
          osVersion: "10",
          local: "false",
          seleniumVersion: "3.5.2",
          resolution: "1366x768",
        },
      },
    },

    //////////////////////////////////////////////////////////////////////////////////
    // Configuration for when using the Selenium service, either locally or remote,  |
    //  like Selenium Grid                                                           |
    //////////////////////////////////////////////////////////////////////////////////
    selenium: {
      // Selenium Server is running locally and is managed by Nightwatch
      selenium: {
        start_process: true,
        port: 4444,
        server_path: Services.seleniumServer
          ? Services.seleniumServer.path
          : "",
        cli_args: {
          "webdriver.gecko.driver": Services.geckodriver
            ? Services.geckodriver.path
            : "",
          "webdriver.chrome.driver": Services.chromedriver
            ? Services.chromedriver.path
            : "",
        },
      },
    },

    "selenium.chrome": {
      extends: "selenium",
      desiredCapabilities: {
        browserName: "chrome",
        chromeOptions: {
          w3c: false,
        },
      },
    },

    "selenium.firefox": {
      extends: "selenium",
      desiredCapabilities: {
        browserName: "firefox",
        "moz:firefoxOptions": {
          args: [
            // '-headless',
            // '-verbose'
          ],
        },
      },
    },
  },
};

function loadServices() {
  try {
    Services.seleniumServer = require("selenium-server");
  } catch (err) {}

  try {
    Services.chromedriver = require("chromedriver");
  } catch (err) {}

  try {
    Services.geckodriver = require("geckodriver");
  } catch (err) {}
}

Your Environment

Executable Version
nightwatch --version 1.3.7
npm --version 6.14.5
yarn --version na
node --version v14.3.0
Browser driver Version
NAME VERSION
chromedriver 84.0.4147.30
geckodriver 0.27.0
safaridriver Included with Safari 12.1 (14607.1.40.1.4)
OS Version
NAME VERSION
macOS Mojave 10.14.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 29 (3 by maintainers)

Most upvoted comments

The moveToElement command is still failing even with Nightwatch v2 …

Response 500 POST /wd/hub/session/f4976621-add3-4029-84a0-06c77facb8c3/actions (16ms) { value: { error: ‘move target out of bounds’, message: ‘(1174, 715) is out of bounds of viewport width (1366) and height (675)’, stacktrace: ‘’ } }

It seems that moveToElement is not scrolling the object into view. As a workaround, I had to manually scroll the window …

browser.execute("scrollTo(0, 600)") // manually scroll the object into view

@IdeaHunter can you raise another issue looks like it’s a different problem