Seeing the below error using split in href

I have 2 environments (test & uat) and has different domains. test is http://sampletest and uat is http://sampleuat. Stored both the domains in global variables under profiles. suffix urls are same in both the environments. Trying to validate anchor tag urls eg I have Release Notes on the main page. URL would be http://sampletest/Menu/ReleaseNotes. for that i wrote the code like below:

WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘path to object’), 20)

List urlReleaseNotes = Arrays.asList(element.getAttribute(‘href’))

println(“Release Notes link—>” + urlReleaseNotes)

arrUrlSegments = urlReleaseNotes.split(’/’)

urlSuffix = arrUrlSegments[(arrUrlSegments.length - 1)].replace(‘Menu/ReleaseNotes’, ‘’)

urlToSwitch = (‘GlobalVariable.G_SiteURL’ + urlSuffix)
println(“Release Notes link—>” + urlToSwitch)

Error in console:
groovy.lang.MissingMethodException: No signature of method: java.util.Arrays$ArrayList.split() is applicable for argument types: (java.lang.String) values: [/]
Possible solutions: split(groovy.lang.Closure), split(groovy.lang.Closure), split(groovy.lang.Closure), wait(), sort(), init()
at TC02_Verifying UI:144)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)
can anyone help me on this?

Not sure why you’re trying to use Arrays.asList() for this?

Try something like…

WebElement element = WebUiCommonHelper.findWebElemen(...)
String href = element.getAttribute(‘href’)
String parts = href.split("/")

// now we have parts[0][N] etc
println parts[2]

Thanks Thomas for the immediate reply and it worked in a different way. I’ll try with the above code also.


And the reason you got the error message is because you were using split on a list (more than one) instead of a string (only one). You would first need to pull one string from the list and then use the split on that string.

1 Like

Thanks Grylion for your answer.

yes I understood and used the string now instead of list. It is working as expected now. :slight_smile: