nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.83k stars 1.32k forks source link

Unable to use keys() and setValue() #2341

Closed harbourc closed 4 years ago

harbourc commented 4 years ago

Describe the bug

I am writing a simple test to open the Google home page, and enter some text in the 'Search' field. My code to navigate to the URL and waitForElementPresent() is working, but when I try to run setValue() or keys(), I am seeing two different error messages, included below.

I have tried the following:

Here is my test.js file:

Sample test

// Please add the sample test here

module.exports = {
  'Search bar displayed on Google Home Page'(driver) {

    driver
      .url('http://www.google.com')
      .assert.urlContains('google')
      .assert.title('Google')
      .waitForElementPresent('input[title=Search]') // this part works
      .pause(5000)
      .setValue('input[title=Search]', 'test123') // error happens here
      .end()
  },
}

Verbose output from setValue() method:

      <error message="An error occurred while running .setValue() command on &lt;input[title=Search]&gt;: " type="error">TypeError [ERR_UNESCAPED_CHARACTERS]: Error while trying to create HTTP request for &#34;/wd/hub/session/610fd8effe2370b09606ede27efb5060/element/[object Object]/value&#34;: Request path contains unescaped characters
    at new ClientRequest (_http_client.js:115:13)
    at Object.request (http.js:42:10)
    at HttpRequest.createHttpRequest (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\http\request.js:138:55)
    at HttpRequest.send (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\http\request.js:217:29)
    at Promise (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\transport\transport.js:193:15)
    at new Promise (&lt;anonymous&gt;)
    at Selenium2Protocol.sendProtocolAction (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\transport\transport.js:191:12)
    at Selenium2Protocol.runProtocolAction (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\transport\jsonwire.js:61:17)
    at Object.setElementValue (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\transport\actions.js:54:10)
    at Selenium2Protocol.executeProtocolAction (C:\Repos\nightwatch-testing\node_modules\nightwatch\lib\transport\transport.js:239:48)</error>

    </testcase>

    <system-err>
      [0;31m  TypeError [ERR_UNESCAPED_CHARACTERS]: An error occurred while running .setValue() command on &lt;input[title=Search]&gt;: [0m
[0;90m       at new ClientRequest (_http_client.js:115:13)
       at Object.request (http.js:42:10)
       at new Promise (&lt;anonymous&gt;)[0m
    </system-err>

Verbose output from keys() method:

Running:  Search bar displayed on Google Home Page

√ Testing if the URL contains 'google' (22ms)
√ Testing if the page title equals 'Google' (12ms)
√ Element <input[title=Search]> was present after 44 milliseconds.
   Response 500 POST /wd/hub/session/4c40b5fe3aae6b6c1882ba8afdadf507/keys (27ms)
   { value:
      { error:
         [ 'Build info: version: \'3.141.5\', revision: \'d54ebd709a\', time: \'2018-11-06T11:58:47\'',
           'System info: host: \'CECEN-CG9200VMM\', ip: \'10.250.14.232\', os.name: \'Windows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_211\'',
           'Driver info: driver.version: unknown' ],
        message: 'sendKeysToActiveElement' },
     status: 9 }
 Error while running .sendKeys() protocol action: sendKeysToActiveElement

Configuration

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "./page_objects",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "server_path" : "./node_modules/selenium-standalone/.selenium/selenium-server/3.141.5-server.jar",
    "log_path" : "./reports",
    "host": "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "C:/Users/christine.harbour/Repos/nightwatch-testing/node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
      "webdriver.gecko.driver" : "",
      "webdriver.edge.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "marionette": true,
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}

Your Environment

Executable Version
nightwatch --version v1.3.4
npm --version 6.9.0
yarn --version N/A
node --version 10.16.3
Browser driver Version
chromedriver 80.0.1
selenium-server 3.141.5

| OS | Version | | Windows 10 | 1607 |

harbourc commented 4 years ago

The issue was solved by adding the following to the nightwatch.json file:

      "desiredCapabilities": {
        "browserName": "chrome",
        "marionette": true,
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions": {
            "w3c": false
        }
      }