WebUI.setText not working

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:
WebUI.focus(findTestObject(“form/sale”))
WebUI.setText(findTestObject(“form/sale”), “1000.00”)

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?

Thanks.

Does your web page has HTML form with autocomple attribute is “on” ? Reference

It is known that the autocomplete attribute makes automated testing difficult. See

… The autocomplete attribute is defined to be ON as default.

It seems that the HTML form’s autocomple attribute was introduced into browsers sometime around June 2018.

Reference: Web Content Accessibility Guidelines (WCAG) 2.1

1 Like

You wrote:

When did you create your tests? Possibly before 2018? If so, your problem was caused by the changes in the W3C HTML Standard. You have no way other than accepting it.

Please search Google for the approaches that others have tried to workaround the problem caused by the autocomplete attribute.

Thanks for the response. This is the not the case for us. Our inputs that are for currency all have autocomplete=off.

1 Like

Oh!


The following is the source code of “WebUI.setText” keyword:

At Line#53, it explicitly calls WebElement.clear() method.

...
                WebElement webElement = WebUIAbstractKeyword.findWebElement(to)
                logger.logDebug(MessageFormat.format(StringConstants.KW_LOG_INFO_CLEARING_OBJ_TXT, to.getObjectId()))
                webElement.clear()
...

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.

Where did you find it?
Could you point me to the URL of the source where webElement.clear() calls the blur event?

Why do you think it is stupid for you? Any rational?

Just for my interest,

The clear() method executes an “Automation Atom”, which is a JavaScript function intended to provide the smallest basic unit of automation functionality for a browser. In the case of clear() , that function sets the value property of the element to an empty string (‘’), then fires the onchange event on the element. The atoms function you’re interested in is bot.action.clear()

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.

In the original post, you wrote:

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.

blur is a javascript event.