I need to get the text in between span tags

i am using this code to get the span text
String APN2 = WebUI.getText(findTestObject('Object_name'))
Xpath :-//div[text()=‘+RandomPincode+’]/preceding-sibling::div[7]/span[@class=“badge transparent”]
data is getting highlighted but still not getting the data when used getText
getting the following error ```(Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get text of object 'Object
Hey Shiva @ShivaRaju, thank you for asking. Maybe try changing the Xpath from div[text()=‘+RandomPincode+’] to either
div[@id='insert id']
div[@class='insert class']
You can always check the documentation on Selection Methods for Web Design here for further information.
Hope this help!
Thanks for the reply
Actually i am getting this from grid , so i need to get the xpath from text only , id /class doenst work for me
You can try //div[contains(text(), ‘RandomPincode’)] to see if it works or not.
Like I said in your other thread, try the above xpath.
You can even use a parameter for your div counter so you can go to other div cells.
Edit:
Also, you can try what @chen.lee has (about using contains), but you again have to prepare your variable for the context you are using it in, like:
//div[contains(text(), "${RandomPincode}"]...
You can try to see if it works or not.
try updating the selector with a relative XPath.
This might help :
Instead of WebUI.getText(findTestObject(“Path”)) use WebUI.getAttribute(findTestObject(“path”), ‘value’)
String text = WebUI.getAttribute(ObjectRepository.findTestObject("path/to/my/object"), "value");