# set text after tab

**URL:** <https://forum.katalon.com/t/set-text-after-tab/11595>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [June 19, 2018, 7:33am UTC](https://forum.katalon.com/t/set-text-after-tab/11595 "2018-06-19T07:33:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jolina\_Yao](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@Jolina\_Yao](https://forum.katalon.com/u/Jolina_Yao)\
**Post date:** [June 19, 2018, 7:33am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/1 "2018-06-19T07:33:29Z")

</div>

I’ve been having trouble finding the desired TestObject using xpath, but I was able to get around by clicking on an object above the desired input field and “tabbed” to the correct input field.

However, the only problem left is to input information using SetText, which takes an TestObject parameter.

Wondering if there is a way to get the current TestObject I have just tabbed to? Or if there is a way to set text to the input field without the need of TestObject?

---

<div class="post-metadata">

**Author:** ![crokatalontest](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@crokatalontest](https://forum.katalon.com/u/crokatalontest)\
**Post date:** [June 19, 2018, 8:37am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/2 "2018-06-19T08:37:58Z")

</div>

Of course you can.  
You need little jquery magic.  
This will set value into active field:

WebUI.executeJavaScript(’$(document.activeElement).val(“YourValue”)’, [])

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [June 19, 2018, 8:55am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/3 "2018-06-19T08:55:03Z")

</div>

can you better describe structure of page?  
can’t you use xpath like : (//xpath\_to\_known\_obj//input)[n]  
this will take n-th element from all you find with x-path expression in ()

---

<div class="post-metadata">

**Author:** ![Jolina\_Yao](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@Jolina\_Yao](https://forum.katalon.com/u/Jolina_Yao)\
**Post date:** [June 20, 2018, 3:54am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/4 "2018-06-20T03:54:09Z")

</div>

> Of course you can.  
> You need little jquery magic.  
> This will set value into active field:  
> WebUI.executeJavaScript(‘$(document.activeElement).val(“YourValue”)’, )

Tried and got the error

```auto
Unable to execute JavaScript. (Root cause: org.openqa.selenium.WebDriverException: unknown error: $ is not defined

```

I attempted the solution posed by [here](https://stackoverflow.com/questions/4853956/how-to-set-a-text-value-for-document-activeelement), and it works!

```auto
WebUI.executeJavaScript('document.activeElement.value = YourValue', [])

```

---

<div class="post-metadata">

**Author:** ![Jolina\_Yao](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@Jolina\_Yao](https://forum.katalon.com/u/Jolina_Yao)\
**Post date:** [June 20, 2018, 6:25am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/5 "2018-06-20T06:25:19Z")

</div>

Follow up question. Is there a way to press “tab” from the current ActiveElement?

---

<div class="post-metadata">

**Author:** ![Jolina\_Yao](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@Jolina\_Yao](https://forum.katalon.com/u/Jolina_Yao)\
**Post date:** [June 20, 2018, 8:31am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/6 "2018-06-20T08:31:07Z")

</div>

Answering my own question, I was able to accomplish through defining the following function:

```auto
	@Keyword	def KeyPress(Keys key) { WebDriver driver = DriverFactory.getWebDriver() Actions act = new Actions(driver); act.sendKeys(key).perform();	}

```

and the following import statements:

```auto
import org.openqa.selenium.interactions.Actions as Actionsimport org.openqa.selenium.JavascriptExecutor as JavascriptExecutorimport org.openqa.selenium.WebDriver as WebDriverimport org.openqa.selenium.WebElement as WebElementimport org.openqa.selenium.Keys as Keysimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.testobject.TestObjectimport com.kms.katalon.core.webui.common.WebUiCommonHelperimport com.kms.katalon.core.webui.driver.DriverFactory

```

---

<div class="post-metadata">

**Author:** ![gumislaw](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gumislaw/32/16104_2.png) [@gumislaw](https://forum.katalon.com/u/gumislaw)\
**Post date:** [April 10, 2022, 8:54pm UTC](https://forum.katalon.com/t/set-text-after-tab/11595/7 "2022-04-10T20:54:24Z")

</div>

Hi!

Thanks for your suggestion I have simiar issue and it works!

I have one question while using:

WebUI.executeJavaScript(‘document.activeElement.value = YourValue’, [])

How to plase YourValue as Variable defined earlier? When I type my variable name in this script it does not work.

---

<div class="post-metadata">

**Author:** ![gumislaw](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gumislaw/32/16104_2.png) [@gumislaw](https://forum.katalon.com/u/gumislaw)\
**Post date:** [April 23, 2022, 3:32pm UTC](https://forum.katalon.com/t/set-text-after-tab/11595/8 "2022-04-23T15:32:57Z")

</div>

Hi!  
I have solved my problem it was trivial:

WebUI.executeJavaScript(“document.activeElement.value = ‘Amount1’”, [])

I just have to use my variable in ‘’.

Have another problem with this, even if I see that the active field is fillin with value from my variable, when it comes to saving the form entered value are not saving ☹ fields are filled out with default value).

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:29am UTC](https://forum.katalon.com/t/set-text-after-tab/11595/9 "2022-08-08T07:29:59Z")

</div>

Archived on August 8, 2022, 7:29am UTC


