How to utilize a new TestObject() xpath in tests?

I’m dealing with a scenario where I am creating a new TestObject(), storing it in a variable, and assigning it an xpath value. My issue is that when I try and use the newly created TestObject it cannot be found and fails. I have verified that the xpath that is contained in the object is exactly the same as the xpath copied from devTools in the browser. At this point I’m pretty stuck, is this even possible to do in Katalon?

Here’s an example of my code:

WebDriver driver = DriverFactory.getWebDriver()

dynamicId = driver.findElements(By.cssSelector(“input[id^=ajax-upload-id-]”));

String transferId = dynamicId[1].getAttribute(“id”)

static TestObject makeTO(String xpath) {

TestObject to = new TestObject()

to.addProperty(“xpath”, ConditionType.EQUALS, xpath)

return to

}

NewbrowseBtn = makeTO("//*[@id=" + transferId + “]”)

WebUI.uploadFile(NewbrowseBtn, ‘C:\\Users\\fschiller\\test_template.dotx’) // This step fails to find the element.

You have this:

NewbrowseBtn = makeTO("//*[@id=" + transferId + "]")

Please try enclosing the value of @id with quotation marks, as follows:

NewbrowseBtn = makeTO("//*[@id=\'" + transferId + "\']")
1 Like

Yes this fixed the issue! Man, escaping a string incorrectly of all things lol. Thank you so much for pointing out my mistake!