.setValue not working after .clearValue
See original GitHub issueLately setValue has been very, very unpredictable. When an input field is empty (for the first time), all goes well. If you clear a field with clearValue however, one of 2 things happens:
- setValue inputs back the data just cleared and appends the new value (the one supposed to be set) on top of it
- setValue inputs nothing
Here’s some --verbose log of when nothing happens:
INFO` Request: POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element
- data: {“using”:“css selector”,“value”:“#numInput”}
- headers: {“Content-Type”:“application/json; charset=utf-8”,“Content-Length”:44} INFO Response 200 POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element (14ms) { state: ‘success’, sessionId: ‘ddd04205-0aee-4877-87f1-5ba68fac489a’, hCode: 275814232, value: { ELEMENT: ‘32’ }, class: ‘org.openqa.selenium.remote.Response’, status: 0 } INFO Request: POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element/32/clear
- data:
- headers: {“Content-Length”:0} INFO Response 200 POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element/32/clear (25ms) { state: ‘success’, sessionId: ‘ddd04205-0aee-4877-87f1-5ba68fac489a’, hCode: 1975991659, value: null, class: ‘org.openqa.selenium.remote.Response’, status: 0 } LOG → Completed command clearValue (48 ms) LOG → Completed command pause (3001 ms) INFO Request: POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element
- data: {“using”:“css selector”,“value”:“#numInput”}
- headers: {“Content-Type”:“application/json; charset=utf-8”,“Content-Length”:44} INFO Response 200 POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element (39ms) { state: ‘success’, sessionId: ‘ddd04205-0aee-4877-87f1-5ba68fac489a’, hCode: 1161376669, value: { ELEMENT: ‘32’ }, class: ‘org.openqa.selenium.remote.Response’, status: 0 } **> INFO Request: POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element/32/value
- data: {“value”:[“8”,“8”,“8”,“-”,“8”,“8”,“8”,“-”,“8”,“8”,“8”]}
- headers: {“Content-Type”:“application/json; charset=utf-8”,“Content-Length”:55} INFO Response 200 POST /wd/hub/session/ddd04205-0aee-4877-87f1-5ba68fac489a/element/32/value (76ms) { state: ‘success’, sessionId: ‘ddd04205-0aee-4877-87f1-5ba68fac489a’, hCode: 1374135861, value: null, class: ‘org.openqa.selenium.remote.Response’, status: 0 } LOG → Completed command setValue (138 ms)**
Basically what happens here is that on the page, we clear an input field containing ‘777-777-777’ (which we set previously) and after that try to set it to ‘888-888-888’. The log says the action is successful, though it isn’t. The field clears fine, but setting the value after that is impossible.
The appending case is the same with logs stating a successful set despite inputting incorrect data.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
clearValue and setValue not working as expected · Issue #5745
Hi Team, I am using webdriverIO V6 and node version 12+. clearValue:- When I use clearValue it doesn't work as expected. Its not...
Read more >clearValue is not clearing the value (still) - Google Groups
Firstly, setValue is misnamed. The documentation states "Sends some text to an element" which is not at all the same as setting (overwriting)...
Read more >Using setValue() method to clear value for currency fields ...
Cause. The setValue() method is not used properly for currency fields. Resolution. Use one of the following formats to clear a value for ......
Read more >Cannot call setValue for element using Appium, Javascript ...
I am using Appium, UIAutomator2, webdriverio and JavaScript to test an app which is running on a virtual device.
Read more >SetValue & ClearValue in WebDriverIO - Part - 9 - YouTube
webdriverio #nodejs #javascript #automationIn this video, I have explained how to automate Login page - setValue and getValue methods in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@Lwdra fixed my issue as well 🎉
Inspired by that command I built one a bit more solid:
Figured out a workaround with a custom clear command:
exports.command = function (browser, selector) { browser .getValue(selector, function(result){ for (c in result.value){ browser.setValue(selector, browser.Keys.BACK_SPACE) } }) return this; };The custom command works essentially like .clearValue by inputting a backspace for each character. It’s ugly but works like a charm.
EDIT Changed the unicode backspace to browser.Keys.BACK_SPACE, because only Chrome supported the
\u0008