Hello,
Just starting to learn Katalon Studio: I feel it is a great tool and I am getting really enthousiastic!
However, I’m struggling with dynamic xpath expressions. I want to adress a row in a table using a variable.
I have an object in the object repository with the following xpath:
_ id(“booked_form”)/table[@class=“login”]/tbody[1]/tr[2]/td[1]/table[1]/tbody[1]/tr[5]/td[1]
_and like to replace the 5 with a variable name.
Any hints how do I do that?
Thanks for your suggestion. I did read that guide but cannot get it to work. Maybe I do not understand. In the test case, I created parameter RowNr:
Then I think I have to link this someway to the object in the object repository, but I think here I do not understand it quite well, now I have a failure during playback. What am I doing wrong?
Test Cases/CalculateTotalBooked FAILED because (of) Unable to click on object ‘Object Repository/Page_AdactIn.com - Select Hotel (1)/td’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_AdactIn.com - Select Hotel (1)/td’ located by ‘By.xpath: //td[count(. | id(“booked_form”)/table[@class=“login”]/tbody[1]/tr[2]/td[1]/table[1]/tbody[1]/tr[RowNr]/td[1]) = count(id(“booked_form”)/table[@class=“login”]/tbody[1]/tr[2]/td[1]/table[1]/tbody[1]/tr[RowNr]/td[1])][count(. | //[@RowNr = ‘5’]) = count(//[@RowNr = ‘5’])]’ not found)
I tried to use Number, but what do I have to fill in for Param in below table?
Still confused about how this is supposed to work.
I’ve been able to use a variable in the xpath with the following method.
I create an object with a path of:
//table[@id=‘sales_dash_table’]/tbody/tr[${Variable}]/td
Then, within the code itself, I use the following:
seasonalityPlanValue= WebUI.getText(findTestObject(‘Page_/table_object_name’, [(‘Variable’) : index]))
The index is part of a loop, so it will be 1, 2, 3, etc as it iterates through.
Invoking a method findTestObject is important. The method implements modifying a given String //*[normalize-space(text())=${Qty}] to a valid XPath expression //*[normalize-space(text())=6].
Without calling the method findTestObject, a placeholder ${Qty} will never be interpolated to 6.
Specifications is a local variable declared as below in the test script
mydate = new Date()
formattedDate = mydate.format(‘MM/dd/yyyy HH mm ss’)
Specifications = “$UpdatedSpecification$formattedDate”
My script fails saying
Unable to find the element located by ‘By.xpath: ///text()[normalize-space(.)=‘${Specifications}’]/parent::’. Please recheck the objects properties to make sure the desired element is located.
2020-08-07 11:31:40.472 INFO c.k.k.c.webui.common.WebUiCommonHelper - [SMART_XPATH] Auto-trying out other XPath values in the test object.
2020-08-07 11:31:40.472 INFO c.k.k.c.webui.common.WebUiCommonHelper - [SMART_XPATH] No working XPath is found.
Please advice how can I use the local variables to pass the values to test objects.
@kazurayam
I am trying to solve a problem of clicking sort arrow in multiple column headers.
Able to click in each column header by hardcoding variable value in script.
How to pick the column name or variable value from the method parameter in the script to click all the column headers based on columnName passed in method parameter?
Error message:
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/CustomznObjects/BranchesListPage/ActivityHistoryTab/oCustomizationAH_ActivityHistoryTable_SortArrowAscend’ located by ‘//th[contains(@id, ‘activitiesTable’) and contains(@title, ‘+columnName’)]/div[@class=“oj-table-column-header”]/div[@class=“oj-table-column-header-asc”]/a[contains(@class, ‘oj-table-column-header-asc’)]’ not found
Got this error message when tried to pass the local variable value as findTestObject(‘CustomznObjects/BranchesListPage/ActivityHistoryTab/oCustomizationAH_ActivityHistoryTable_SortArrowAscend’,[‘text’:’+columnName’]
Locator used:
//th[contains(@id, ‘activitiesTable’) and contains(@title, ‘${text}’)]/div[@class=“oj-table-column-header”]/div[@class=“oj-table-column-header-asc”]/a[contains(@class, ‘oj-table-column-header-asc’)]
@arthi.vigneshwari Maybe you are trying too soon. Have you tried to insert a wait statement, such as
WebUI.waitForElementVisible(findTestObject(‘CustomznObjects/BranchesListPage/ActivityHistoryTab/oCustomizationAH_ActivityHistoryTable_SortArrowAscend’,[‘text’:‘Activity’])
@grylion54 Thanks for your reply. Exception is not due to wait issue.It is due to xpath not found. Am not sure how to pass the method parameter in findTestObject parameter value.Please help with it.