clearValue is not clearing the value (still)

1,282 views
Skip to first unread message

Nathan Youngman

unread,
Oct 12, 2018, 2:24:36 PM10/12/18
to NightwatchJs
How do you update the values in an existing form to test update functionality?

Firstly, setValue is misnamed. The documentation states "Sends some text to an element" which is not at all the same as setting (overwriting) the value of an element.

So then there's clearValue, but apparently it doesn't actually work, and the issues people have opened over the years were unceremoniously closed without resolution.


So I try Yan C's suggestion:

.click("input#first_name").clearValue("input#first_name").setValue("input#first_name", "night")

and Andrei Rusu's:

.setValue("input#first_name", [browser.Keys.CONTROL,'a']).setValue("input#first_name", "night")

None of these things are working for me in Nightwatch.js 1.0.11 (beta), using latest Node.js 10.12.0, java 11,28 and latest Chrome 69.

Has anyone managed to get clearValue to work reliably in Nightwatch 1.x?

Thank you, Nathan.

Nathan Youngman

unread,
Oct 12, 2018, 3:30:25 PM10/12/18
to NightwatchJs

Yan C's click before clear method is working for me now. 🤷‍♂️

.click("#first_name").clearValue("#first_name").setValue("#first_name", "night")

Another option that appears to work is dropping down to JavaScript or in this case JQuery:

.execute("$('#first_name').val('night')")

It's a shame that the clearValue API is so fragile and the setValue API is poorly named for what it does.

Cheers,
Nathan.

Per T

unread,
Oct 13, 2018, 2:29:41 AM10/13/18
to NightwatchJs
I also use a custom command setVal to make sure that I don't forget clearing value before setting it.

// commands/setVal.js:

exports.command = function(sel, val){
// Fix for setValue() not clearing value first.
// https://github.com/nightwatchjs/nightwatch/issues/4

this.clearValue(sel);
this.setValue(sel, val);
this.execute(function(){});
return this;
};

Reply all
Reply to author
Forward
0 new messages