How to change the value in xpath

Hello,

I am wondering if there any way to change the xpath value?

My object looks like this:

Now while running the test case, I need to replace the value 4 (that is marked) to a dynamic value. This value I already capture in my code as below:

int rows_count = rows_table.size()

println(rows_count)

I need to replace that 4 with rows_count. Do i sounds strange? or is that a valid question, I am wondering :slight_smile:

Thanks,

Hi Neethu,

You are talking about dynamic xpath. Yes, that is possible. Try to look in the link below on how to handle it.
There are a lot of answers in there that you can try on.

Hope that helps. . . :smiley:

To make it simple, try this one out:

Edit your xpath and change the changing value to a variable like this ${index} . Something like:

//input[@id='complaintAssignmentSubview:complainAssignmentFormLcomplaintAssignmentDataTable${index}:chooseUserCommandButtonId']

Or if it doesnt work, replace the single quotes to double quotes and enclose your variable into a single quote. Something like:

//input[@id="complaintAssignmentSubview:complainAssignmentFormLcomplaintAssignmentDataTable'${index}':chooseUserCommandButtonId"]

To do an event do this:

//apply your variable in the parameter (case sensitive)
WebUI.click(findTestObject("Your_object", [(index)] : row_count]))
WebUI.getText(findTestObject("Your_object", [(index)] : row_count]))

Hope that it works on you. . . :smiley:

hi @Arnel,

Thanks for your reply. I was going through the link you have provided in the first reply and I found some solution too :slight_smile:

int rows_count = rows_table.size()

println(rows_count)

String newpath = (‘complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:’+rows_count+’:chooseUserCommandButtonId’)

println newpath

WebUI.modifyObjectProperty(findTestObject(‘Object Repository/assignreactive/main/chooseuser4’), ‘xpath’, ‘equals’, newpath, true)

WebUI.delay(2)

So it returned like this: from console:

2019-04-11 18:03:31.430 e[39mDEBUGe[0;39m e[36mtestcase.assignreactivedispute -e[0;39m e[39m31: rows_count = rows_table.size()e[0;39m
2019-04-11 18:03:31.430 e[39mDEBUGe[0;39m e[36mtestcase.assignreactivedispute -e[0;39m e[39m32: println(rows_count)e[0;39m
5
2019-04-11 18:03:31.445 e[39mDEBUGe[0;39m e[36mtestcase.assignreactivedispute -e[0;39m e[39m33: newpath = “complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:” + rows_count + ":chooseUserCommandButtonId"e[0;39m
2019-04-11 18:03:31.445 e[39mDEBUGe[0;39m e[36mtestcase.assignreactivedispute -e[0;39m e[39m34: println(newpath)e[0;39m
complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:5:chooseUserCommandButtonId
2019-04-11 18:03:31.445 e[39mDEBUGe[0;39m e[36mtestcase.assignreactivedispute -e[0;39m e[39m35: modifyObjectProperty(findTestObject(“Object Repository/assignreactive/main/chooseuser4”), “xpath”, “equals”, newpath, true)e[0;39m

It worked … Thank you!!

Oh Great! Cheers! :beers:

Hi @Arnel,

Eventhough modify object property was successful, I am unable to click on the new modified object. Here is my code:

println(rows_count)
3
newpath = “complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:” + rows_count + “:chooseUserCommandButtonId”
println(newpath)
complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:3:chooseUserCommandButtonId
modifyObjectProperty(findTestObject(“Object Repository/assignreactive/main/chooseuser4”), “xpath”, “equals”, “//input[@id=‘complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:’+rows_count+’:chooseUserCommandButtonId’]”, true)
click(findTestObject(“Object Repository/assignreactive/main/chooseuser4”))

Unable to find the element located by ‘By.xpath: //input[@id=‘complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:4:chooseUserCommandButtonId’]’. Please recheck the objects properties to make sure the desired element is located.

click(findTestObject(“Object Repository/assignreactive/main/chooseuser4”))
com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/assignreactive/main/chooseuser4’com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:48)at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)

i think eventhough modifi object property is sucessful, the property is not changed actually.
Am i missing something? I tried to get the attribute , id after modifying the object, but that too failed.

Thanks,

Hello @Arnel,

I found a solution from another discussion on the same topic.

println(rows_count)

String newpath = (‘id("complaintAssignmentSubview:complaintAssignmentForm:complaintAssignmentDataTable:’+rows_count+’:chooseUserCommandButtonId")’)

println(newpath)

TestObject dynamicObject = new TestObject(‘dynamicObject’).addProperty(‘xpath’, com.kms.katalon.core.testobject.ConditionType.EQUALS, newpath, true)

WebUI.waitForElementVisible(dynamicObject, 3)

WebUI.click(dynamicObject)

Now i am able to clik on the new object.

Thanks.