问题
I am trying to setup a new Nightwatch project for the purpose of automating a simple Google search page. My assert for searchbox present on page passes, but I am not able to perform any mouse/keyboard action on the elements (Searchbox
, or SearchButton
)
Note: I am running Nightwatch version 1.0
.
Test case:
module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure Site title matches
.assert.visible('input[name=q]')
.setValue('input[name=q]', 'nightwatchjs') // send values
.click('button[name=btnG]') // click on search box
.pause(1000)
.end()
},
};
I have also tried with this approach:
var setValue = function(sel, value) {
$(sel).val(value).change();
};
module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure Site title matches
.assert.visible('input[name=q]')
.execute(setValue, ['input[name=q]', 'nightwatchjs'])
.click('button[name=btnG]') // click on search box
.pause(1000)
.end()
},
};
This is the output log:
[Google] Test Suite
Running: Demo test Google
- √ Element was visible after 133 milliseconds.
- √ Testing if the page title equals "Google" - 18 ms.
- √ Testing if element is visible - 61 ms.
Error log:
Error while running .setElementValue() protocol action: unknown error: call function result missing 'value'
TimeoutError: An error occurred while running .setValue() command on : {"status":-1, "state":"", "value": {"message":"unknown error: call function result missing 'value'", "error":[" (Session info: chrome=77.0.3865.120)"," (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17763 x86_64)"]},"errorStatus":13,"error":"unknown error: call function result missing 'value'","httpStatusCode":200} at process._tickCallback (internal/process/next_tick.js:68:7) NoSuchElementError: An error occurred while running .click() command on : at process._tickCallback (internal/process/next_tick.js:68:7)
回答1:
Try to click() on input first, and then use setValue(), sometimes it helps
来源:https://stackoverflow.com/questions/58437187/setvalue-method-in-nightwatch-is-not-working