How to override WebUI.setText

When you use the command WebUI.setText, it does the following:

  1. It clears the current value.
  2. It raises the input events, including the blur event.
  3. It sets the new value.
  4. It raises the input events, including the blur event.

How do I override the WebUI.setText so it works like how an actual user would replace an input value without having go back through all my tests and adding lots of repetitive commands.

I need setText to work in the following way in one command:

  1. It clears the current value.
  2. It raises the input events, should not raise blur event, focus should not change.
  3. It sets the new value.
  4. It raises the input events, including the blur event.

Thanks.

How about creating a Keyword that clears the text, then sets the text and then all you need do is globally replace your “WebUI.setText()” with your new Keyword?

@Keyword
public void clearSetText(TextObject tobj, String myText) {
   WebUI.clearText(tobj)
   WebUI.setText(tobj, myText)
   WebUI.sendKeys(tobj, Keys.chord(Keys.ENTER))
}

To globally Search and Replace, you can use several different third party applications, such as Microsoft VSCode, or Komodo Edit (both free), then you replace
WebUI.setText

with

CustomKeywords.'com.Tools.clearSetText'

See if that works.

Edit: you will have to use your name of the Keyword class and replace my “com.Tools”.

1 Like

Thanks for the response. This has sent me in the right direction. Using the following keyword, I am able to make this work.

@Keyword
public void clearSetText(TestObject obj, String value) {
	WebUI.focus(obj)
	WebUI.sendKeys(obj, Keys.chord(Keys.CONTROL, 'a'))
	WebUI.sendKeys(obj, Keys.chord(Keys.BACK_SPACE))
	WebUI.sendKeys(obj, value)
	WebUI.sendKeys(obj, Keys.chord(Keys.TAB))
}