Use escaped xpath from testobject to call WebElement

Hi everybody,
I am new to Selenium and Katalon, which is a great product by the way.

I am currently facing a challenge I get knot out of it.

I would like to retrieve the xpath of an existing testobject in my object repository and use this xpath to call a webelement in order to manipulate a text between a span-tag (this is the qay I try, but mayby there are other solutions).

I was able to get the xpath, but because of the characters used in the path (slashes and quotes) it is not complete. This is what I have so far:

def checkBuffer = ''
def xpath = ''

checkBuffer = ''
xpath = ''
checkBuffer = WebUI.getText(findTestObject('Page_Case/formData_SiteName'))
TestObject toSiteName = findTestObject('Page_Case/formData_SiteName')
xpath =  '//' + toSiteName.findProperty('xpath').value.replace('/', '//').replace(""", "\"")

WebElement wSiteName = driver.findElement(By.xpath(xpath))

This gives me the following xpath:
/div[contains(@class, “app-wrapper”)]/div[@data-layout =“form”]/div[@data-header-text=“General”]/span[contains(@class, “app-field-SiteID”)]/span[@class=“app-control-inner app-field-data”]

Actually it should look like this:
//div[contains(@class, ‘app-wrapper’)]//div[@data-layout =‘form’]//div[@data-header-text=‘General’]//span[contains(@class, ‘app-field-SiteID’)]//span[@class=‘app-control-inner app-field-data’]

Could anybody please help me with that? I am also openminded for other solutions to change the string between span-tags.

Thanks in advance.

Does nobody have an idea? :neutral_face:

Hi @itBoy

If the purpose is to get the XPath from a TestObject and then use Selenium to retrieve the WebElement, then that method is already available:

TestObject yourTestObject = findTestObject("your test object id");
WebElement element = WebUiCommonHelper.findWebElement(yourTestObject, 30);

Could you put your code into code formatting block? There is a weird mixture of quotemarks and I don’t know which are correct. And what is stored in your TestObject? Are slashes correct there?

this worked fine so far. I was not aware of the WebUiCommonHelper.
But, I am still not able to change the text within the SPAN-tags. Is there a way to use this WebElement-object to manipulate the text between the SPAN-elements?

See the following: