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.run(TC02_Verifying UI:144)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:339)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:330)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:309)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:235)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1600353399109.run(TempTestCase1600353399109.groovy:25)
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]..parts[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.

2 Likes

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: