Dynamic Xpath is not working by passing variable to the xpath

Hi, I am passing variable as SearchText = “Studies”

My dynamic xpath is Xpath=//one-app-launcher-menu-item/a//p/b[text()=’${SearchText}’]
which is not working.

If i give hardcoded xpath as xpath as //one-app-launcher-menu-item/a//p/b[text()=‘Studies’] which is working.

while passing the variable in Searchtext , the xpath is not able to searched and give error as "Unable to find the element located by ‘By.xpath: //one-app-launcher-menu-item/a//p/b[text()=’${SearchText}’]’. Please recheck the objects properties to make sure the desired element is located. "
Please let me know if i am missing anything and how to dynamically pass the variable.

You need to pass a list of key:value pairs as the 2nd parameter to findTestObject method.
For example:

WebUI.setText(findTestObject(testObjectId, ['SearchText': 'Studies']), "Happy birthday!")

Please share your test case script if you have further question.

1 Like

Thanks!! it worked