# Passing variables to object in Windows App Testing

**URL:** <https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107>\
**Category:** Desktop Testing\
**Tags:** desktop, windows, katalon-studio\
**Created:** [February 20, 2020, 8:17am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107 "2020-02-20T08:17:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![piotr.kochanek.2](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/piotr.kochanek.2/32/16104_2.png) [@piotr.kochanek.2](https://forum.katalon.com/u/piotr.kochanek.2)\
**Post date:** [February 20, 2020, 8:17am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/1 "2020-02-20T08:17:14Z")

</div>

Hi  
I’m trying to pass a String “KOI” to my object named “menuItem” to click on a selected position in menu by:

Windows.click(findWindowsObject(‘Object Repository/mainWindow/menuItem’, [(‘itemName’) : “KOI”] ))

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/b/baf4739448b29f7345f79dffe970c6c349aee0c1.png)

//MenuItem[@Name=“KOI”] works fine, but //MenuItem[@Name=“${itemName}”] doesn’t.

Log:

```
2020-02-20 09:14:19.862 DEBUG testcase.TEST - 8: switchToWindow(findWindowsObject("Object Repository/mainWindow/mainFrame"))
lut 20, 2020 9:14:20 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: OSS
2020-02-20 09:14:20.033 DEBUG testcase.TEST - 9: click(findWindowsObject("Object Repository/mainWindow/menuItem", ["itemName":"KOI"]))
2020-02-20 09:14:21.419 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'APS00076262-MB', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: io.appium.java_client.windows.WindowsDriver
Capabilities {appTopLevelWindow: 808ba, javascriptEnabled: true, platform: WINDOWS, platformName: WINDOWS}
Session ID: B4334F10-B953-4EF6-B814-E43A3B191EFA
*** Element info: {Using=xpath, value=//MenuItem[@Name="${itemName}"]} (Root cause: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'APS00076262-MB', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: io.appium.java_client.windows.WindowsDriver
Capabilities {appTopLevelWindow: 808ba, javascriptEnabled: true, platform: WINDOWS, platformName: WINDOWS}
Session ID: B4334F10-B953-4EF6-B814-E43A3B191EFA
*** Element info: {Using=xpath, value=//MenuItem[@Name="${itemName}"]}

```

---

<div class="post-metadata">

**Author:** ![duyluong](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/duyluong/32/1116_2.png) [@duyluong](https://forum.katalon.com/u/duyluong)\
**Post date:** [February 21, 2020, 4:29am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/2 "2020-02-21T04:29:44Z")

</div>

@piotr.kochanek.2

Passing variables for Windows object is not supported for this moment. We will consider to support in the near feature.

Pleas track the development status via this issue: [https://github.com/katalon-studio/katalon-studio/issues/274](https://github.com/katalon-studio/katalon-studio/issues/274)

Thanks for your report.

---

<div class="post-metadata">

**Author:** ![piotr.kochanek.2](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/piotr.kochanek.2/32/16104_2.png) [@piotr.kochanek.2](https://forum.katalon.com/u/piotr.kochanek.2)\
**Post date:** [February 21, 2020, 9:07am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/3 "2020-02-21T09:07:22Z")

</div>

Hey @duyluong, thanks for reply.

Is there any workaround for such a scenario?  
Im creating an order with random ID, lets say “123321”. The ID shows on a message box where can I getText() the order ID. Now I’m opening a list of current orders and I want to right-click on the row with orderID = 123321. Can I do it without passing a variable to the object?

Maybe something like:  
Windows.rightClick(findWindowsObject(where XPATH=“//Window/Pane[3]/Pane[1]/Pane[1]/Pane[1]/Pane[1]/List[1]/ListItem[contains(@Name, ‘MY\_STRING\_VAR’)]”)) ?

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/2/2d1496d3595e40ec86070d3b5fcd98e36fc87963.png)

---

<div class="post-metadata">

**Author:** ![duyluong](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/duyluong/32/1116_2.png) [@duyluong](https://forum.katalon.com/u/duyluong)\
**Post date:** [February 21, 2020, 10:31am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/4 "2020-02-21T10:31:46Z")

</div>

@piotr.kochanek.2

You can get the object’s locator and set the locator again.

Example:

```auto
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import org.apache.commons.text.StringSubstitutor as StringSubstitutor
import com.kms.katalon.core.testobject.WindowsTestObject as WindowsTestObject

WindowsTestObject obj = findWindowsObject('your object id')

String MY_STRING_VAR = '123321'

String newLocator = StringSubstitutor.replace(obj.getLocator(), [('MY_STRING_VAR') : MY_STRING_VAR])
obj.setLocator(newLocator)

println(obj.getLocator())

```

---

<div class="post-metadata">

**Author:** ![piotr.kochanek.2](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/piotr.kochanek.2/32/16104_2.png) [@piotr.kochanek.2](https://forum.katalon.com/u/piotr.kochanek.2)\
**Post date:** [February 21, 2020, 11:41am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/5 "2020-02-21T11:41:32Z")

</div>

@duyluong

That’s exactly what I needed. It worked. Thanks a lot 🕶.

---

<div class="post-metadata">

**Author:** ![Jass](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/jass/32/9588_2.png) [@Jass](https://forum.katalon.com/u/Jass)\
**Post date:** [September 15, 2020, 9:14am UTC](https://forum.katalon.com/t/passing-variables-to-object-in-windows-app-testing/40107/6 "2020-09-15T09:14:56Z")

</div>

Closed on September 15, 2020, 9:14am UTC


