I am currently trying to create a basic script using nightwatch.js that will launch Google and input text into the search bar. However, I am encountering difficulties when using both setValue()
methods to enter text into the element.
Below is my script:
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"]')
.pause(5000)
.setValue('input[title="Search"]', 'test123') // issue occurs here
.end()
},
}
Upon using setValue()
, I encounter the following error message:
Error while running .setElementValue() protocol action: TypeError [ERR_UNESCAPED_CHARACTERS]: Error while trying to create HTTP request for "/wd/hub/session/ed0680ce58544facf2a4b193eccbc223/element/[object Object]/value": Request path contains unescaped characters at new ClientRequest (_http_client.js:115:13) at Object.request (http.js:42:10) at HttpRequest.createHttpRequest at new Promise () at Selenium2Protocol.sendProtocolAction
It seems like .setValue()
is attempting to send Object object
as the WebElement
ID in the request URL.
The script successfully performs the assert
and
.waitForElementPresent('input[title="Search"]')
actions, indicating that the element exists on the page. To ensure sufficient loading time, I added a pause(5000)
before sending keys. Additionally, I've tried clicking with .click()
prior to utilizing .keys()
in an attempt to focus on the element.
While I believe the syntax to be accurate, my limited experience with nightwatch could be a contributing factor to the problem.
A similar issue was reported by another user, but unfortunately, it remains unresolved: setValue method in Nightwatch is not working
I am using chromedriver
version 80.0.3987.16
The nightwatch
version being utilized is 1.3.4
To install chromedriver
, I used npm install chromedriver
and configured the path to chromedriver.exe
in my nightwatch.json
file:
{
"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" : "./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"
}
}
}
}
If anyone could provide insight into what might be causing this issue, I would greatly appreciate it.