# WebUI.setText not working

**URL:** <https://forum.katalon.com/t/webui-settext-not-working/93058>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [July 23, 2023, 9:34pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058 "2023-07-23T21:34:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clayton\_Friesen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/clayton_friesen/32/16104_2.png) [@Clayton\_Friesen](https://forum.katalon.com/u/Clayton_Friesen)\
**Post date:** [July 23, 2023, 9:34pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/1 "2023-07-23T21:34:09Z")

</div>

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.

> **[\[WebUI\] Set Text | Katalon Docs](https://docs.katalon.com/docs/create-tests/keywords/keyword-description-in-katalon-studio/web-ui-keywords/webui-set-text#ariaid-title1)**
>
> Description

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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 23, 2023, 10:12pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/2 "2023-07-23T22:12:16Z")

</div>

Does your web page has HTML form with **autocomple** attribute is “on” ? [Reference](https://www.w3schools.com/tags/att_form_autocomplete.asp)

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

> <https://stackoverflow.com/questions/50677760/selenium-clear-command-doesnt-clear-the-element>

… 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](https://www.w3.org/TR/WCAG21/#input-purposes)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 23, 2023, 10:49pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/3 "2023-07-23T22:49:37Z")

</div>

You wrote:

> [@Clayton\_Friesen](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Clayton\_Friesen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/clayton_friesen/32/16104_2.png) [@Clayton\_Friesen](https://forum.katalon.com/u/Clayton_Friesen)\
**Post date:** [July 24, 2023, 12:28am UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/4 "2023-07-24T00:28:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 24, 2023, 12:43am UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/5 "2023-07-24T00:43:43Z")

</div>

> [@Clayton\_Friesen](#):
>
> Our inputs that are for currency all have autocomplete=off.

Oh!

* * *

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

> <https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/webui/keyword/builtin/SetTextKeyword.groovy>

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

```auto
...
                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:

- [SetText doesn't clear previous value](http://forum.katalon.com/t/settext-doesnt-clear-previous-value/18262)

- [How to clear() input fields in web? - #6 by Bojan\_Ognjenovic](http://forum.katalon.com/t/how-to-clear-input-fields-in-web/8549/6)

---

<div class="post-metadata">

**Author:** ![Clayton\_Friesen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/clayton_friesen/32/16104_2.png) [@Clayton\_Friesen](https://forum.katalon.com/u/Clayton_Friesen)\
**Post date:** [July 24, 2023, 6:58pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/6 "2023-07-24T18:58:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 24, 2023, 10:12pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/7 "2023-07-24T22:12:20Z")

</div>

> [@Clayton\_Friesen](#):
>
> went through this and found that the webElement.clear() works but it is call the [blur event](https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event) after.

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

> [@Clayton\_Friesen](#):
>
> This is so stupid that it works this way.

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

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 25, 2023, 1:26am UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/8 "2023-07-25T01:26:00Z")

</div>

> [@Clayton\_Friesen](#):
>
> So setText, clear the value, calls blur event, set the new value, calls blur event.

Just for my interest,

> **[WebDriver](https://www.w3.org/TR/webdriver1/#element-clear)**
>
> WebDriver is a remote control interface
> that enables introspection and control of user agents.
> It provides a platform- and language-neutral wire protocol
> as a way for out-of-process programs
> to remotely instruct the behavior of web browsers.

> <https://stackoverflow.com/questions/15167429/what-does-webelement-clear-do-to-textboxes>

> The `clear()` method executes an [“Automation Atom”](https://github.com/SeleniumHQ/selenium/wiki/Automation-Atoms), 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()`](https://github.com/SeleniumHQ/selenium/blob/master/javascript/atoms/action.js#L83)

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.

---

<div class="post-metadata">

**Author:** ![Clayton\_Friesen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/clayton_friesen/32/16104_2.png) [@Clayton\_Friesen](https://forum.katalon.com/u/Clayton_Friesen)\
**Post date:** [July 25, 2023, 2:29pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/9 "2023-07-25T14:29:23Z")

</div>

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.

> **[WebDriver](https://www.w3.org/TR/webdriver1/#element-clear)**
>
> WebDriver is a remote control interface
> that enables introspection and control of user agents.
> It provides a platform- and language-neutral wire protocol
> as a way for out-of-process programs
> to remotely instruct the behavior of web browsers.

You can also just run it. Have an input with blur event that logs when it runs, setText fires the blur event twice.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 25, 2023, 2:39pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/10 "2023-07-25T14:39:14Z")

</div>

In the original post, you wrote:

> [@Clayton\_Friesen](#):
>
> 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”.

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.

---

<div class="post-metadata">

**Author:** ![Clayton\_Friesen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/clayton_friesen/32/16104_2.png) [@Clayton\_Friesen](https://forum.katalon.com/u/Clayton_Friesen)\
**Post date:** [July 25, 2023, 3:24pm UTC](https://forum.katalon.com/t/webui-settext-not-working/93058/11 "2023-07-25T15:24:22Z")

</div>

blur is a javascript event.
