Skip to content

Error while running .getElementText() protocol action: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used. #4407

@reallymello

Description

@reallymello

Description of the bug/issue

I'm not sure if this issue is due to invalid syntax or if this should be valid, but if I try to check the placeholder text using syntax such as

    browser.expect
      .element('#searchbox_input')
      .attribute('placeholder')
      .text.to.equal('Search without being tracked');

The test passes and also throws an exception

√ Expected element <#searchbox_input> to have attribute "placeholder" equal: "Search without being tracked" (18ms)
    Error   Error while running .getElementText() protocol action: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

Image

If I change the assertion to this format then I do not receive the error

    browser.expect
      .element('#searchbox_input')
      .to.have.attribute('placeholder')
      .which.equals('Search without being tracked');

Steps to reproduce

Run the sample test

Sample test

import { NightwatchAPI, NightwatchTests } from 'nightwatch';

const localizationTests: NightwatchTests = {
  before: () => {
    browser.url('http://www.duckduckgo.com');
  },
  'Search input has placeholder text': (browser: NightwatchAPI) => {
    // This passes, but then fails with the invalid driver instance error
    browser.expect
      .element('#searchbox_input')
      .attribute('placeholder')
      .text.to.equal('Search without being tracked');

    // Works ok below
    // browser.expect
    //   .element('#searchbox_input')
    //   .to.have.attribute('placeholder')
    //   .which.equals('Search without being tracked');
  },
  after: () => {
    browser.end();
  },
};

export default localizationTests;

Command to run

npx nightwatch localizationTests.ts

Verbose Output

npx nightwatch nightwatch\tests\localizationTests.ts --verbose


[Localization Tests] Test Suite
──────────────────────────────────────────────────────────────
⠋ Starting ChromeDriver on port 9515...
⠙ Starting ChromeDriver on port 9515...
   Request POST /session  
   {
     capabilities: {
       firstMatch: [ {} ],
       alwaysMatch: {
         browserName: 'chrome',
         'goog:chromeOptions': {
           binary: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
         }
       }
     }
⠹ Starting ChromeDriver on port 9515...

⠦ Starting ChromeDriver on port 9515...
   Response 200 POST /session (456ms)
   {
     value: {
       capabilities: {
         acceptInsecureCerts: false,
         browserName: 'chrome',
         browserVersion: '135.0.7049.116',
         chrome: {
           chromedriverVersion: '135.0.7049.114 (63fd8a7d9d09e41ba37b84386c85d5f249f848f7-refs/branch-heads/7049@{#2175})',
           userDataDir: 'C:\\Users\\agent\\AppData\\Local\\Temp\\scoped_dir70252_1298596070'
         },
         'fedcm:accounts': true,
         'goog:chromeOptions': { debuggerAddress: 'localhost:51708' },
         networkConnectionEnabled: false,
         pageLoadStrategy: 'normal',
         platformName: 'windows',
         proxy: {},
         setWindowRect: true,
         strictFileInteractability: false,
         timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
         unhandledPromptBehavior: 'dismiss and notify',
         'webauthn:extension:credBlob': true,
         'webauthn:extension:largeBlob': true,
         'webauthn:extension:minPinLength': true,
         'webauthn:extension:prf': true,
         'webauthn:virtualAuthenticators': true
       },
       sessionId: 'facd7bb4ca6c79cee55193b269af2eee'
     }
ℹ Connected to ChromeDriver on port 9515 (671ms).                                                                                                                                                                                                                      
  Using: chrome (135.0.7049.116) on WINDOWS.

 Received session with ID: facd7bb4ca6c79cee55193b269af2eee

 → Running [before]:
 
 → Running command: url ('http://www.duckduckgo.com')
  ⠋ Loading url: http://www.duckduckgo.com
   Request POST /session/facd7bb4ca6c79cee55193b269af2eee/url  
  ⠏ Loading url: http://www.duckduckgo.com
   Response 200 POST /session/facd7bb4ca6c79cee55193b269af2eee/url (873ms)
  ℹ Loaded url http://www.duckduckgo.com in 875ms                                                                                                                                                                                                                      
 → Completed command: url ('http://www.duckduckgo.com') (875ms)
 → Completed [before].



  Running Search input has placeholder text:
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 → Running [beforeEach]:
 → Completed [beforeEach].
 
 → Running command: expect.element ('#searchbox_input')
   Request POST /session/facd7bb4ca6c79cee55193b269af2eee/elements  
   { using: 'css selector', value: '#searchbox_input' }
   Response 200 POST /session/facd7bb4ca6c79cee55193b269af2eee/elements (5ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.2B61F76EE85407F82F28A305CDFB006D.d.8921C1EC054B3459B05A60D48992B265.e.11'
       }
     ]
  }
   Request GET /session/facd7bb4ca6c79cee55193b269af2eee/element/f.2B61F76EE85407F82F28A305CDFB006D.d.8921C1EC054B3459B05A60D48992B265.e.11/text  

   Request POST /session/facd7bb4ca6c79cee55193b269af2eee/execute/sync  
   {
     script: '/* getAttribute */return (function(){return (function(){var d=this||self;function f(a,b){function c(){}c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a};var h=Array.prototype.indexO... (6082 characters)',
     args: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.2B61F76EE85407F82F28A305CDFB006D.d.8921C1EC054B3459B05A60D48992B265.e.11',
         ELEMENT: 'f.2B61F76EE85407F82F28A305CDFB006D.d.8921C1EC054B3459B05A60D48992B265.e.11'
       },
       'placeholder'
     ]
  }
   Response 200 GET /session/facd7bb4ca6c79cee55193b269af2eee/element/f.2B61F76EE85407F82F28A305CDFB006D.d.8921C1EC054B3459B05A60D48992B265.e.11/text (7ms)
   { value: '' }
   Response 200 POST /session/facd7bb4ca6c79cee55193b269af2eee/execute/sync (9ms)
   { value: 'Search without being tracked' }
  √ Expected element <#searchbox_input> to have attribute "placeholder" equal: "Search without being tracked" (18ms)
 → Completed command: expect.element ('#searchbox_input') (18ms)
 → Running [afterEach]:
 → Completed [afterEach].

  ✨ PASSED. 1 assertions. (31ms)
 → Running [after]:
 
 → Running command: end ()
 
 → Running command: session ('delete', [Function])
   Request DELETE /session/facd7bb4ca6c79cee55193b269af2eee  

   Response 200 DELETE /session/facd7bb4ca6c79cee55193b269af2eee (33ms)
   { value: null }
 → Completed command: end () (50ms)
 → Completed command: session ('delete', [Function]) (34ms)
 → Completed [after].
 Wrote HTML report file to: C:\Projects\nightwatch-i18next\tests_output\nightwatch-html-report\index.html

 Wrote JSON report file to: C:\Projects\nightwatch-i18next\tests_output\CHROME_135.0.7049.116__localizationTests.json
 Wrote Rerun Json report file to: C:\Projects\nightwatch-i18next\tests_output\minimal_report.json
 Wrote XML report file to: C:\Projects\nightwatch-i18next\tests_output\CHROME_135.0.7049.116__localizationTests.xml
    Error   Error while running .getElementText() protocol action: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

  ✖ NightwatchAssertError
   Expected element <#searchbox_input> text to equal: "Search without being tracked" - expected "equal 'Search without being tracked'" but got: "null" (5068ms)

    Error location:
    C:\Projects\nightwatch-i18next\nightwatch\tests\localizationTests.ts:23
    ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     21 |     // This passes, but then fails with the invalid driver instance error
     22 |     browser.expect
     23 |       .element('#searchbox_input') 
     24 |       .attribute('placeholder')
     25 |       .text.to.equal('Search without being tracked');
    ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

  Error
   unhandledRejection: Expected element <#searchbox_input> text to equal: "Search without being tracked" - expected "equal 'Search without being tracked'" but got: "null" (5068ms)
    at Object.Search input has placeholder text (C:\Projects\nightwatch-i18next\nightwatch\tests\localizationTests.ts:23:8)

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  ️TEST FAILURE (7.143s):
   - 1 error during execution;
   - 0 assertions failed; 1 passed

Nightwatch Configuration

// Refer to the online docs for more details:
// https://nightwatchjs.org/gettingstarted/configuration/
//

//  _   _  _         _      _                     _          _
// | \ | |(_)       | |    | |                   | |        | |
// |  \| | _   __ _ | |__  | |_ __      __  __ _ | |_   ___ | |__
// | . ` || | / _` || '_ \ | __|\ \ /\ / / / _` || __| / __|| '_ \
// | |\  || || (_| || | | || |_  \ V  V / | (_| || |_ | (__ | | | |
// \_| \_/|_| \__, ||_| |_| \__|  \_/\_/   \__,_| \__| \___||_| |_|
//             __/ |
//            |___/

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: ['nightwatch/test'],

  // See https://nightwatchjs.org/guide/concepts/page-object-model.html
  page_objects_path: [],

  // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
  custom_commands_path: [],

  // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
  custom_assertions_path: [],

  // See https://nightwatchjs.org/guide/extending-nightwatch/adding-plugins.html
  plugins: [],

  // See https://nightwatchjs.org/guide/concepts/test-globals.html
  globals_path: '',

  webdriver: {},

  test_workers: {
    enabled: true,
  },

  test_settings: {
    default: {
      disable_error_log: false,
      launch_url: 'http://localhost',

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

      desiredCapabilities: {
        browserName: 'chrome',
      },

      webdriver: {
        start_process: true,
        server_path: '',
      },
    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
          args: [
            //'--no-sandbox',
            //'--ignore-certificate-errors',
            //'--allow-insecure-localhost',
            //'--headless=new'
          ],
        },
      },

      webdriver: {
        start_process: true,
        server_path: '',
        cli_args: [
          // --verbose
        ],
      },
    },
    spanishChrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        chromeOptions: {
          prefs: {
            'intl.accept_languages': 'es-ES,es',
          },
          args: ['--lang=es-ES'],
        },
      },

      webdriver: {
        start_process: true,
        server_path: '',
        cli_args: [
          // --verbose
        ],
      },
    },
  },
};

Nightwatch.js Version

3.12.1

Node Version

22.13.1

Browser

Chrome 125

Operating System

Windows 11

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions