A few years ago we created a large number of tests for our project and everything worked great. Then we got an update to Studio, I think around version 5 and all our WebUI.setText stopped working. At the time we just left it and now we want to fix our tests. The problem is WebUI.setText is suppose to clear the previous value, but that changed. It now appends the previous value. I need setText to work as documented.
For example, the page is loaded:
text input “form/sale” has a value of “0.00”
The following two lines get run:
The result is:
text input “form/sale” has value “0.001000.00”.
The result should be:
text input “form/sale” should have value “1000.00”.
The documentation for WebUI.setText says:
Set the value of an input field, as though you type it in. It also clears the previous value of the input field.
Using setText does not clear the previous value, it is only appending to it.
How do I make setText work the way it is documented?
This code calls WebElement.clear() to clear, as documented, the previous values. But unfortunately, for some reason, it does not work. All I want to say here is that Katalon Studio is not really causing the problem. The cause lies in the WebDriver & browser layer.
You should have a wider scope of search for workaround. Even in this Katalon User forum, you can find several posts related to “WebUI.setText”. For example:
I went through this and found that the webElement.clear() works but it is call the blur event after. So setText, clear the value, calls blur event, set the new value, calls blur event. The problem for me is on the input blur event, we format the currency value. This is so stupid that it works this way.
I think that the WebDriver client library in Java implements WebElement.clear() right as the W3C WebDriver specification specifies. I wouldn’t see it is stupid.
I’m not calling the clear command, i’m calling the setText command. One command on one input to replace the value. It is behaving like a user put focus on the input, cleared the value, clicked or tabbed out of focus, then put focus back on the input to set the new value.
I have to script multiple commands on every input to replicate a user interaction because what should be one command behaves like it is two commands. This is the opposite of what a tool does that is suppose to help me.
You can see in the document that the clear command fires the events.
You can also just run it. Have an input with blur event that logs when it runs, setText fires the blur event twice.
I tried to reproduce your case on my side. I made a HTML with an <input> element. I made a Katalon Test Case to interact with the page. The WebUI.setText(testobject, '1000.00') worked just fine. I did not see your insident (having the field ‘0.001000.00’) reproduced. Possibly your HTML is different from my humble HTML and the difference caused the different behavior of WebUI.setText(). I can not see anything about your HTML. So I have no more words to say.