Skip to content

findByText(...).click() may throw Request path contains unescaped characters unhandled exception #4394

@reallymello

Description

@reallymello

Description of the bug/issue

When I use findByText to locate an element and chain .click() I expect the element to be clicked, but on some runs Nightwatch throws the error
Error while trying to create HTTP request for "/session/7c32b94cdb6a038e3cb3537f8e900549/element/[object Object]/click": Request path contains unescaped characters

for the same locator in the same spot in the test. The text locator itself is just the text ' OK ' because the button itself has no id or unique classes.

When this occurs the Nightwatch process exits early, does not run teardown, and does not close the session or browser--resulting in timeout errors in BrowserStack

Steps to reproduce

Run a test similar to

myPageObject.element.findByText(' OK ').click();

This usually works, but occasionally it throws the above mentioned error. By the look of the error mesage maybe it is not resolved/located before click is issued? Since it shows [object Object] in the request--unless that is just a console output quirk?

Sample test

myPageObject
      .element('@addClaimsResultsGrid')
      .findByText(firstClaimName)
      .assert.present();
    myPageObject
      .element('@addClaimsResultsGrid')
      .findByText(secondClaimName)
      .assert.present();

// Issue occurs here
    myPageObject.element.findByText(' OK ').click();

Command to run

npx nightwatch sampleTest.ts

Verbose Output

→ Running command: element.find ()
   Request POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements  
   {
     using: 'css selector',
     value: '[data-testid="add-claims-grid"] [role="grid"]'
  }
   Response 200 POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements (11ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559'
       }
     ]
  }
 → Completed command: element.find () (12ms)

 → Running command: element.find ({ By(xpath, .//*[text()="Claim_1_37387942619"]) })
   Request POST /session/7c32b94cdb6a038e3cb3537f8e900549/element/f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559/elements  
   { using: 'xpath', value: './/*[text()="Claim_1_37387942619"]' }
   Response 200 POST /session/7c32b94cdb6a038e3cb3537f8e900549/element/f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559/elements (9ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2543'
       },
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2544'
       }
     ]
  }
 → Completed command: element.find ({ By(xpath, .//*[text()="Claim_1_37387942619"]) }) (10ms)

 → Running command: element.find ()
   Request POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements  
   {
     using: 'css selector',
     value: '[data-testid="add-claims-grid"] [role="grid"]'
  }

 → Running command: assert.ok ()
  √ Passed [ok]: Testing if the element <WebElement: f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2543> is present.
 → Completed command: assert.ok () (0ms)
   Response 200 POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements (9ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559'
       }
     ]
  }
 → Completed command: element.find () (10ms)

 → Running command: element.find ({ By(xpath, .//*[text()="Claim_2_37387942619"]) })
   Request POST /session/7c32b94cdb6a038e3cb3537f8e900549/element/f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559/elements  
   { using: 'xpath', value: './/*[text()="Claim_2_37387942619"]' }
   Response 200 POST /session/7c32b94cdb6a038e3cb3537f8e900549/element/f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1559/elements (8ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2545'
       },
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2546'
       }
     ]
  }
 → Completed command: element.find ({ By(xpath, .//*[text()="Claim_2_37387942619"]) }) (9ms)

 → Running command: element.find ({ By(xpath, .//*[text()=" OK "]) })
   Request POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements  
   { using: 'xpath', value: './/*[text()=" OK "]' }

 → Running command: assert.ok ()
  √ Passed [ok]: Testing if the element <WebElement: f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.2545> is present.
 → Completed command: assert.ok () (0ms)
   Response 200 POST /session/7c32b94cdb6a038e3cb3537f8e900549/elements (49ms)
   {
     value: [
       {
         'element-6066-11e4-a52e-4f735466cecf': 'f.919F2D1CC641E26C9AFA34BB7F0329F0.d.F9F1C3D4102E77470CB89BD4E1FC0360.e.1527'
       }
     ]
  }
 → Completed command: element.find ({ By(xpath, .//*[text()=" OK "]) }) (51ms)

 → Running command: element().clickElement ()
    Error   Error while running .clickElement() protocol action: Error while trying to create HTTP request for "/session/7c32b94cdb6a038e3cb3537f8e900549/element/[object Object]/click": Request path contains unescaped characters

  ✖ TypeError
   Error while trying to create HTTP request for "/session/7c32b94cdb6a038e3cb3537f8e900549/element/[object Object]/click": Request path contains unescaped characters
    Stack Trace :
    at new ClientRequest (node:_http_client:185:13)
    at Object.request (node:http:102:10)
    at HttpRequest.createHttpRequest (C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\nightwatch\lib\http\request.js:233:49)
    at HttpRequest.send (C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\nightwatch\lib\http\request.js:413:29)
    at C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\nightwatch\lib\transport\selenium-webdriver\httpclient.js:99:17
    at new Promise (<anonymous>)
    at HttpClient.send (C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\nightwatch\lib\transport\selenium-webdriver\httpclient.js:58:14)
    at Executor.execute (C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\selenium-webdriver\lib\http.js:441:33)
    at Driver.execute (C:\Users\reallyMello\projects\my-nightwatch-rm\node_modules\selenium-webdriver\lib\webdriver.js:744:38)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)

Nightwatch Configuration

Nightwatch.js Version

3.11.1

Node Version

22.13.0

Browser

Chrome 135

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