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
Thanks,
Arnel
April 11, 2019, 9:29am
2
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.
Hi Team,
I am facing difficulties in handling dynamic xpath. I have a table, the contents of table changes depending on the previous steps.
Ex :
//[@id=âaaaa.CountryRolePhasesView.readyByDate_editor.0â]
//[@id=âaaaa.CountryRolePhasesView.readyByDate_editor.1â]
//*[@id=âaaaa.CountryRolePhasesView.readyByDate_editor.2â]
In above example, number changes. How can we handle this ? can we pass a variable to test objects to achieve this ? If yes, please provide the procedure for the same.
Also, âŚ
Hope that helps. . .
Arnel
April 11, 2019, 9:57am
3
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. . .
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
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!!
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.