nightwatch icon indicating copy to clipboard operation
nightwatch copied to clipboard

.getLocationInView() is returning 'unknown command: Cannot call non W3C standard command while in W3C mode'

Open AutomatedTester opened this issue 2 years ago • 4 comments

Describe the bug

When calling getLocationInView() in W3C mode it returns 'unknown command: Cannot call non W3C standard command while in W3C mode'

Sample test

Details in https://discord.com/channels/618399631038218240/935468415731253258/950846771926564905

Verbose output

debug.log

<!-- Include the verbose output, if possible (run nightwatch with `--verbose` argument) -->

Configuration

nightwatch.json

{
  "your": { "config": "here" }
}

Your Environment

Executable Version
nightwatch --version VERSION
npm --version VERSION
yarn --version VERSION
node --version VERSION
Browser driver Version
NAME VERSION
OS Version
NAME VERSION

AutomatedTester avatar Mar 08 '22 21:03 AutomatedTester

await this.getLocationInView('@addButton');

Verbose Output:

 → Running command: getLocationInView ({name, __index, __selector, locateStrategy, pseudoSelector, parent, resolvedElement, abortOnFailure, suppressNotFoundErrors, timeout...}, [Function])
   Request POST /session/c714f1d2e2856573017956a2a7a4fccd/elements  
   { using: 'css selector', value: '[test-id="addButton"]' }
   Response 200 POST /session/c714f1d2e2856573017956a2a7a4fccd/elements (10ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': '902f2b33-df72-49e2-9eaa-3b3834b10afd'
       }
     ]
  }
   Request GET /session/c714f1d2e2856573017956a2a7a4fccd/element/902f2b33-df72-49e2-9eaa-3b3834b10afd/location_in_view  
   Response 404 GET /session/c714f1d2e2856573017956a2a7a4fccd/element/902f2b33-df72-49e2-9eaa-3b3834b10afd/location_in_view (1ms)
   {
     value: {
       error: 'unknown command',
       message: 'unknown command: Cannot call non W3C standard command while in W3C mode',
       stacktrace: ''
     }
  }

Configuration:

'chrome': {
  desiredCapabilities : {
    'browserName' : 'chrome',
    'goog:chromeOptions' : {
      w3c: true,
      args: [
        // '--no-sandbox',
        // '--ignore-certificate-errors',
        // '--allow-insecure-localhost',
        // '--headless'
      ]
    }
  },

qa-danny avatar Mar 08 '22 21:03 qa-danny

This is due to using a non-w3c command in w3c mode. getLocationInView is marked as deprecated. Either we can set w3c:false in config and use this command or instead try using getElementRect.

gravityvi avatar Apr 18 '22 09:04 gravityvi

Let's see about deprecating this. It's not coming up often and can be replaced with executeScript or using getElementRect

AutomatedTester avatar Jan 17 '23 11:01 AutomatedTester

Hello, we're using this command (in nightwatch 1.7) to ensure clicking on an anchor does lead to the right position, and getElementRect only returns absolute position within the page, not relative to current viewport.

I believe when you advise to use executeScript, you mean something along the lines return document.querySelector(selector).getBoundingClientRect(); ? How can I use it with a selector param from a page elements definition ?

Cactusbone avatar Feb 09 '23 14:02 Cactusbone