Hello, I have a box with a text value inside. So I want to call it using
.clearValue(element.durInput)
but it's not clearing the value and so when I use .setValue it appends the new value instead of replacing. I wanted to instead use the code for keypress to press ctrl-a and then backspace to clear it. I'm using the code
browser.keys([browser.Keys.CONTROL, "a"])
browser.keys("8")
but I'm sure it's wrong since it's not working. Any idea how to make it work? Thanks in advance
Hi, thanks for stopping by. I suggest asking for assistance on the mailing list: http://groups.google.com/forum/#!forum/nightwatchjs
sure, thanks
What was the resolution on this issue? I am seeing this issue but only when running the test against IE 11. Chrome and Firefox clear the field just fine.
Having the exact same issue on chrome 63
I have the exact same issue too - on chrome 62
Having same issue
same issue
Any updates on this?
Clicking on the element prior to clearing does the trick for me.
.click(elementId)
.clearValue(elementId)
.setValue(elementId, 'A car floats in space');
@Treyone solution works, for those having trouble changing value in a textarea element, however this special treatment (ie. bringing the element into focus), is not required before performing setValue() and clearValue() on input elements though.
note: this odd behavior is still present as of nightwatch v0.9.19.
I have the exact same issue too - on chrome 87
you can try to do
browser.click('input[type="text"]')
browser.keys(browser.Keys.BACK_SPACE)
maybe you can try to do:
On the newest version of nightwatch and still having this issue, please fix
On the newest version of nightwatch and still having this issue, please fix
I'm facing the same issue. Please let me know if any fix is available
On the newest version of nightwatch and still having this issue, please fix
I created this custom method clearInputValue & its working perfectly every-time:
module.exports = {
clearInputValue: function (locator) {
const browser = this.api;
this.waitForElementVisible(locator);
this.click(locator);
this.getValue(locator, function (result) {
const length = result.value.length;
for (let i = 0; i < length; i++) {
browser.keys([browser.Keys.DELETE]);
}
browser.keys([browser.Keys.TAB]); //This is optionally done to remove focus from locator field
});
return this;
},
};
Also, one can similarly create setInputValue, this time I'm using Class-style commands:
module.exports = class SetInputValue {
command(locator, value) {
return new Promise((resolve) => {
const browser = this.api;
browser
.waitForElementVisible(locator)
.click(locator)
.getValue(locator, function (result) {
const length = result.value.length;
for (let i = 0; i < length; i++) {
browser.keys([browser.Keys.DELETE]);
}
browser.setValue(locator, value, function () {
browser.keys([browser.Keys.TAB]);
resolve();
});
});
});
}
};
E.g:
Call simply _setInputValue(myLocator)_ to clear existing value or to set empty value
Call _setInputValue(myLocator, '12.34');_ to set value of 12.34 in input text field
Still experiencing this on the newest
Most helpful comment
Clicking on the element prior to clearing does the trick for me.