# How to make xpath calls directly from a Katalon script?

**URL:** <https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [March 12, 2020, 12:51am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989 "2020-03-12T00:51:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy.coleman](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jeremy.coleman](https://forum.katalon.com/u/Jeremy.coleman)\
**Post date:** [March 12, 2020, 12:51am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/1 "2020-03-12T00:51:38Z")

</div>

Man, i feel a bit slow even having to ask this, but I’ve spent a good amount of time hunting for it and still haven’t figured it out. What command do i use if i want to locate an object on a page by its xpath reference instead of its Object Repository path?

Like if i wanted to use WebUI.click(), what would be the xpath equivalent of findTestObject()?

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 12, 2020, 2:06am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/2 "2020-03-12T02:06:52Z")

</div>

Hey Jeremy

I’m not entirely sure what you’re asking. If you want to create TestObject “live” in memory (instead of building them and storing them in the Object Repo) you can use `makeTO()` (note: you can change to using xpath instead of css if you wish).

> [@Creation of Test Object in Object Repository in Runtime](http://forum.katalon.com/t/creation-of-test-object-in-object-repository-in-runtime/10333/2):
>
> Hi Indurajan I use this: /\*\* \* Construct a Katalon-compatible TestObject in memory. \* @param css (String) The CSS selector used to find the target element. \* @return (TestObject) The constructed TestObject. \*/ static TestObject makeTO(String css) { TestObject to = new TestObject() to.addProperty("css", ConditionType.EQUALS, css) return to }

Also documented here:

[https://docs.katalon.com/katalon-studio/docs/manage-web-test-object.html](https://docs.katalon.com/katalon-studio/docs/manage-web-test-object.html)

If that’s not what you want to do, let me know.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [March 12, 2020, 2:07am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/3 "2020-03-12T02:07:56Z")

</div>

You wouldn’t be able to use WebUI.click() without referencing a test object, but you could always just use pure selenium to do the same thing:

```
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = driver.findElement(By.xpath("//my//xpath"))
element.click()
```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [March 12, 2020, 3:14am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/4 "2020-03-12T03:14:43Z")

</div>

Alternatively you can create a TestObject instance specifying a XPath expression as its property.

```auto
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
...
TestObject tObj = new TestObject()
tObj.addProperty("xpath", ConditionType.EQUALS, "//my//xpath")
WebUI.verifyElementPresent(tObj)
...

```

---

<div class="post-metadata">

**Author:** ![Jeremy.coleman](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jeremy.coleman](https://forum.katalon.com/u/Jeremy.coleman)\
**Post date:** [March 12, 2020, 3:52am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/5 "2020-03-12T03:52:26Z")

</div>

Thanks @Brandon_Hein, I think that gets me mostly what I was looking for.

@Russ_Thomas Basically, its for when I’m scripting by hand, and I have to check an attribute or click on a particular element that, for whatever reason, I can find pretty quickly/easily through xpath, but would be a hassle for me to track down in my object repo.

I’m just trying to be efficient with my coding practices, so that i’m as comfortable using xpath to access DOM elements as i am with pulling them into my script from the object repo.

@kazurayam, Nice i didn’t realize you could instantiate and assign objects that way, very cool. I’ll have to read up on that TestObject, that looks useful!

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [March 12, 2020, 4:57am UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/6 "2020-03-12T04:57:58Z")

</div>

> [@Jeremy.coleman](#):
>
> I’m just trying to be efficient with my coding practices, so that i’m as comfortable using xpath to access DOM elements as i am with pulling them into my script from the object repo.

You’re on the right track. Several of us actually don’t even use the object repository at all 😉

---

<div class="post-metadata">

**Author:** ![Kautsar.romy2](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kautsar.romy2/32/16104_2.png) [@Kautsar.romy2](https://forum.katalon.com/u/Kautsar.romy2)\
**Post date:** [January 5, 2021, 12:04pm UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/7 "2021-01-05T12:04:12Z")

</div>

Hello @Brandon_Hein, How about set text into target Xpath without object, but use pure selenium ?

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [January 5, 2021, 3:11pm UTC](https://forum.katalon.com/t/how-to-make-xpath-calls-directly-from-a-katalon-script/40989/8 "2021-01-05T15:11:16Z")

</div>

It’s the same thing, but you would use the sendKeys() method:

```
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = driver.findElement(By.xpath("//my//xpath"))
element.sendKeys("abc")

```

I would recommend reviewing the Selenium API if you want to go down this route, as there are a lot of useful methods at your disposal:

[https://www.javadoc.io/doc/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebDriver.html](https://www.javadoc.io/doc/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebDriver.html)
