Set Text and change event

I have problem with setting value to input field (and propably textareas) and change events.
In input field I have script in change event what validates value to number (eg. 1.000) and if value is empty validator add value to 0.000.
If I try to add field value to 1, Set Text first clears field and then add number 1 to field. However every time value will be 0.0001.
Problem is that Set Text first clear field + trigger change event and after value set it trigger second time change event.


Test script:
WebUI.setText(findTestObject(‘input_id_of_field’), ‘1’)

I have send messages with support and have try something else (customkeywords etc.):
def Boolean SetValueAndVerify(Object fieldname, String dateValue, String dateToVerify){
Integer SecondsToFailure = 2;
WebUI.sendKeys(fieldname, Keys.chord(Keys.CONTROL, ‘a’))
WebUI.sendKeys(fieldname, dateValue)
WebUI.sendKeys(fieldname, Keys.chord(Keys.TAB))
→ works fine with Firefox but not in Chrome. Keys.CONTROL, ‘a’) doesn’t work in Chrome at all.

WebUiCommonHelper.findWebElement(findTestObject("/path/to/object"), 30).clear()
WebUI.sendKeys(findTestObject("/path/to/object"), yourValue)
→ Works exactly like Set Text. …clear() trigger change and so does sendKeys

Does anybody any ideas to emulate input field as user normally does:
Click field, clear or delete containing text, type new text and after all that click somewhere else (or Enter, Tab.) so change event is triggered?

“Does anybody any ideas to emulate input field as user normally does:
Click field, clear or delete containing text, type new text and after all that click somewhere else (or Enter, Tab.) so change event is triggered?”

Could we get it by?

  • WebUI.clear(findTestObject())
    or createCustomKeywork
    def clear(TestObject obj) {
  • WebUI.sendKeys()
  • object)

Yes, have try those. Not work.

(WebUI.clear(findTestObject()) -> No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.clear())

Basic problem is simply. When I click input element, delete all text and add new, onchange should trigger after all. Now …clear() trigger onchange, sendKeys trigger onchange. Click another object does not because onchange has been triggered allready.
And Set Text does it twice. Oh my.

I see.
WebUI.clear() is a custom keyword so it we have to create it before calling (Katalon Studio will add it as built-in keyword in next build).

Does it mean that when we do the input manually and we clear the input, onchange trigger will not be fired?

Could I access the UI for more information?

UI is unreachable, but to test this case is simply:

Create html page, add one input field:

and create test:
WebUI.setText(findTestObject(‘input_id_of_field’), ‘1’)

I have try to use custom keywords (clear), Set Text, sendKeys, etc. Only solution to set text correctly to input field (as normaly user does) is create custom keyword and use JavascriptExecutor to call jquery functions in page.
((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(’$("#id_of_element")’.val("’+numbervalue+’");’);
((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(’$("#id_of_element").trigger(“change”);’);

And this should not be the right way to emulate user who insert text (or number, whatever) in html from input field!

Last message lost input field, try again:

<input id='id_of_field' type='text' value='5.000' onchange='this.value = parseFloat((this.value==''?0:this.value)).toFixed(3);"/>

Is there a fix for this?

Are you gonna ever fix this?

Something you have done, setText trigger onchange event once. But after clearing field, not after text set.

hi guys, do you found the ways to solved this problem? I’m facing same problem here, the onchange function triggered after clearing field, not after set the text.

any solutions yet?

As Ilkka discovered, to gain the best control of these fields you should use JavaScript. That’s the only way you can be sure that what is happening is what you intended.

If you want the clear to happen, you could try:


And then set the text.