Clicking on a field with a randomly-generated number


#1

I’ve been unable to find a solution to my issue. I have an input field where I’m using static text with a randomly-generated number appended. I’m doing this because the page I’m testing only allows me to deactivate the test I’m running instead of letting me delete it completely once I’m finished.

In my script, I’m using
import org.apache.commons.lang.RandomStringUtils as RandomStringUtils

and using it in

WebUI.setText(findTestObject(‘Object Repository/Page_/input_Player Group Name_PlaceHoldertxtPlayerGroupName’), ‘Test_Group_’ + RandomStringUtils.randomNumeric(5))

It generates perfectly. However, within my script I then navigate to the page where it’s listed with the others like it. Since I’ve been trying to get this to work (and if/when it actually does) there is/will be other items on the page containing the name “Test_Group_”.

Any idea how to get the script to key in on the correct one?


#2

If I’m following your scenario correctly…

String randNum = ‘Test_Group_’ + RandomStringUtils.randomNumeric(5)

WebUI.setText(findTestObject(‘Object Repository/Page_/input_Player Group Name_PlaceHoldertxtPlayerGroupName’), randNum)

WebUI.setText(findTestObject(‘Object Repository/Page_/SomethingElse’), randNum)


#3

Thanks for the speedy response. I really appreciate the assistance.

I’m not sure if I implemented your solution correctly or not, but based on what I’m getting I guess not.

I replaced WebUI.setText(findTestObject(‘Object Repository/Page_/input_Player Group Name_PlaceHoldertxtPlayerGroupName’), ‘Test_Group_’ + RandomStringUtils.randomNumeric(5))

with

String randNum = ‘Test_Group_’ + RandomStringUtils.randomNumeric(5)

WebUI.setText(findTestObject(‘Object Repository/Page_/input_Player Group Name_ctl00ctl00ActiveTabContentPlaceHolderRootActiveTabContentPlaceHoldertxtPlayerGroupName’),
randNum)

When I try to click on it via

WebUI.click(findTestObject(‘Object Repository/Page_/a_Test_Group_’), randNum)

I get

click(findTestObject(“Object Repository/Page_/a_Test_Group_”), randNum) FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.lang.String) values: [TestObject - ‘Object Repository/Page_/a_Test_Group_’, Test_Group_40992]
Possible solutions: click(com.kms.katalon.core.testobject.TestObject)

but I’m not understanding that last line…

It did at least see that “Test_Group_” was generated as “Test_Group_40992” so that’s a step in the right direction…


#4

So it appeared to me, you wanted to append 'Test_Group_' + random-string to your various TestObject names. If that is not the case, then you need to clarify. For example, perhaps you don’t want Test_Group to be part of the string stored in the variable but instead, use:

String randNum = RandomStringUtils.randomNumeric(5)

WebUI.setText(findTestObject(‘Object Repository/Page_/input_Player Group Name_PlaceHoldertxtPlayerGroupName’), ‘Test_Group_’ + randNum)

Then in your click…

If this is still wrong, you need to send more info about what you’re trying to achieve. Perhaps the following advice will help:


#5

I managed to figure it out. All I needed to do was nuke everything from the xpath and set the following in the Selector Editor field (this is taken from the XPATH as reported by devtools):

//*[@id=“ActiveTabContentPlaceHolderRoot_ActiveTabContentPlaceHolder_gridPlayerGroups”]/tbody/tr[(last() -1)] /td[3]/a

the /tr[ ] was the part that kept changing. The last iteration of this was /tbody/tr[20]/td[3]/a. the -1 is there because there’s a footer on the page.

Then the script just needs to click it like usual:
WebUI.click(findTestObject(‘Page_/a_Edit’))


#6

Cool. Glad you got it working. I marked your own post as the solution :wink: