# Javascript to send text to a field with xpath

**URL:** <https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [June 4, 2019, 8:36am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949 "2019-06-04T08:36:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 4, 2019, 8:36am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/1 "2019-06-04T08:36:23Z")

</div>

I Have a field to which Im unable to sendKeys or setText so i tried using Java script Executor . But I’m unable to pass the Test object as param

**Custom keyword**  
@keyword  
def sendKeysJS(TestObject to, String input) {  
WebElement element = WebUiCommonHelper.findWebElement(findTestObject(to)  
WebDriver driver = DriverFactory.getWebDriver()  
String jScript = document.getElementById(element).value = input  
JavascriptExecutor executor = (JavascriptExecutor)driver  
executor.executeScript(jScript)  
}

**Called:**  
CustomKeywords.‘customPackage.Utils.sendKeysJS’(findTestObject(‘CreatePIObject/AssignPI/Reg’), ‘abc’)

Error: Caused by: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘Object Repository/CreatePIObject/AssignPI/Reg’]  
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)

Can somebody help me with setting text to a field with xpath (Unable to set the text using "SetText "as it doesn’t enter the complete text

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [June 4, 2019, 8:45am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/2 "2019-06-04T08:45:22Z")

</div>

Try this and see how it works for you

```auto
import com.kms.katalon.core.webui.common.WebUiCommonHelper
 
WebElement element = WebUiCommonHelper.findWebElement(findTestObject('your/object'),30)
WebUI.executeJavaScript("arguments[0].value='Your Value'", Arrays.asList(element))

```

---

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 4, 2019, 9:29am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/3 "2019-06-04T09:29:13Z")

</div>

This works! @hpulsford THANKS

---

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 4, 2019, 5:47pm UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/4 "2019-06-04T17:47:38Z")

</div>

@hpulsford Now I have another issue with the same field…I used the above to input the value but the entered value soon disappears when i perform the next action .  
I have an input field to which I’m entering the text using the above suggested but the next step is to click on search . The filed gets cleared **before** it goes to the click step. Any help here ?

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [June 5, 2019, 8:03am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/5 "2019-06-05T08:03:10Z")

</div>

Sounds like an issue with your application to me, if you do the exact same thing manually (doing it yourself) do you experience the same behaviour. As in enter the text and then immediately click the search button.

Does the text disappear when search is clicked? or does it disappear after a certain amount of time?

---

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 5, 2019, 8:56am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/6 "2019-06-05T08:56:18Z")

</div>

No,This does not happen when I manually enter the text . The text stays there even after the search results are displayed .

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [June 5, 2019, 9:13am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/7 "2019-06-05T09:13:54Z")

</div>

No idea why that could be happening, Could you share the html of the element

---

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 5, 2019, 9:29am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/8 "2019-06-05T09:29:19Z")

</div>

![18%20PM](https://europe1.discourse-cdn.com/katalon/original/2X/6/62253a968b3880ac2b7cc52615d3f1655ed7a3b2.png) The "Registration Number is the filed to which I’m trying to enter the Text .

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [June 5, 2019, 10:56am UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/9 "2019-06-05T10:56:17Z")

</div>

hmm not sure, might be best to raise a new topic with the correct title therefore others will be able to help you out. You can include all the information above just a fresh topic as this is a diffrerent issue 🙂

---

<div class="post-metadata">

**Author:** ![mbordoloi](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mbordoloi](https://forum.katalon.com/u/mbordoloi)\
**Post date:** [August 11, 2020, 4:17pm UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/10 "2020-08-11T16:17:35Z")

</div>

I have am having the same issue. I am using a date picker. So, my scenario is the text field which accepts date picker value is a readonly text filed and on selecting a date it updates the value of a hidden text field. But when i am automating it, it is setting the value but is clearing it out immediately.

 ![scriptkatalon](https://europe1.discourse-cdn.com/katalon/original/2X/d/d295eb19876cb4de4ce29cf0352544b4482ac886.jpeg) ![scriptkatalon](https://europe1.discourse-cdn.com/katalon/original/2X/d/d295eb19876cb4de4ce29cf0352544b4482ac886.jpeg)

---

<div class="post-metadata">

**Author:** ![gauthamkarthik534](https://avatars.discourse-cdn.com/v4/letter/g/a587f6/32.png) [@gauthamkarthik534](https://forum.katalon.com/u/gauthamkarthik534)\
**Post date:** [October 10, 2020, 6:00pm UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/11 "2020-10-10T18:00:47Z")

</div>

Please follow below tutorial

---

<div class="post-metadata">

**Author:** ![mbordoloi](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mbordoloi](https://forum.katalon.com/u/mbordoloi)\
**Post date:** [November 5, 2020, 3:48pm UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/12 "2020-11-05T15:48:41Z")

</div>

Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![gdearest07](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gdearest07/32/22419_2.png) [@gdearest07](https://forum.katalon.com/u/gdearest07)\
**Post date:** [May 29, 2023, 3:21pm UTC](https://forum.katalon.com/t/javascript-to-send-text-to-a-field-with-xpath/26949/15 "2023-05-29T15:21:47Z")

</div>

@gauthamkarthik534 , what tutoriar? I cannot see any tutorial neither below nor above
