Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 1

=============== ROOT CAUSE =====================

Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 1

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html

================================================

04-09-2025 11:15:35 p.m. Test Cases/New Test Case

Elapsed time: 6.662s

Test Cases/New Test Case FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to select option by value ‘{"_typename":“UserRole”,“id”:“36ebef6a-91c7-4a6a-be65-a1d4faaafd42”,“name”:“DISPATCH1”,“type”:“User”}’ of object 'Object Repository/New Folder/Page/select_DISPATCH1ADMINDISPATCH2’ using regular expression

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:117)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:43)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.selectOptionByValue(SelectOptionByValueKeyword.groovy:69)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.execute(SelectOptionByValueKeyword.groovy:42)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByValue(WebUiBuiltInKeywords.groovy:1244)

at New Test Case.run(New Test Case:36)

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:448)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:137)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:125)

at TempTestCase1744220734640.run(TempTestCase1744220734640.groovy:25)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 1

{“__typename”:“UserRole”,“id”:“36ebef6a-91c7-4a6a-be65-a1d4faaafd42”,“name”:“DISPATCH1”,“type”:“User”}

^

at com.kms.katalon.core.helper.KeywordHelper.match(KeywordHelper.java:22)

at com.kms.katalon.core.webui.common.WebUiCommonHelper.selectOrDeselectOptionsByValueByRegularExpression(WebUiCommonHelper.java:290)

at com.kms.katalon.core.webui.common.WebUiCommonHelper.selectOrDeselectOptionsByValue(WebUiCommonHelper.java:273)

at com.kms.katalon.core.webui.common.WebUiCommonHelper$selectOrDeselectOptionsByValue.call(Unknown Source)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.selectOrDeselectOptionsByValue(SelectOptionByValueKeyword.groovy:74)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.access$0(SelectOptionByValueKeyword.groovy)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword$_selectOptionByValue_closure1.doCall(SelectOptionByValueKeyword.groovy:58)

at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword$_selectOptionByValue_closure1.call(SelectOptionByValueKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:35)

… 18 more

1 Like

The log is not enough to understand your problem.

Please show the source of your Test Case script, around the statement which calls WebUI.selectOptionByValue().

Also please show the HTML source of the page, especially the “Selector” part you want to get access to.

I guess, the HTML element you tried to get access to is not a HTML <select><option>... element. It could be for example <div> elements controlled by JavaScript.

Katalon’s WebUI.selectOption* keywords assumes <select><option> elements, therefore it would never work on the HTMLs controlled by the modern JavaScript libraries, such as React, which probably don’t generate a <select><options> sequence.

The error arises because SelectOptionByValue keyword interprets your input value as a regular expression (regex) by default, and the JSON string contains special regex characters (e.g., {, }, "). To fix this:

Solution 1: Disable Regex Matching

Add isRegex: false to force an exact text match instead of regex:

WebUI.selectOptionByValue(
    findTestObject('Object Repository/New Folder/Page/select_DISPATCH1ADMINDISPATCH2'),
    '{"_typename":"UserRole","id":"36ebef6a-91c7-4a6a-be65-a1d4faaafd42","name":"DISPATCH1","type":"User"}',
    false, // isRegex = false
    10 // Timeout
)

Solution 2: Escape Regex Characters

If you must use regex (e.g., partial matching), escape special characters in the JSON:

import java.util.regex.Pattern

def jsonValue = '{"_typename":"UserRole","id":"36ebef6a-91c7-4a6a-be65-a1d4faaafd42","name":"DISPATCH1","type":"User"}'
// Escape regex-sensitive characters
def escapedValue = Pattern.quote(jsonValue)

WebUI.selectOptionByValue(
    findTestObject('Object Repository/New Folder/Page/select_DISPATCH1ADMINDISPATCH2'),
    escapedValue,
    true, // isRegex = true
    10
)

Why This Happens

  • SelectOptionByValue uses regex by default (isRegex: true).
  • The JSON text contains {, ", and other characters that are invalid in regex patterns unless escaped.

Additional Checks

  1. Verify the Actual <option> Value:
    Inspect the HTML to ensure the value attribute of the <option> element exactly matches the JSON string (including quotes):
<option value='{"_typename":"UserRole","id":"36ebef6a-91c7-4a6a-be65-a1d4faaafd42","name":"DISPATCH1","type":"User"}'>DISPATCH1</option>
  1. Use XPath for Dynamic Values:
    If the id or other fields are dynamic, locate the element using XPath with partial matches:
def dynamicOption = findTestObject('Your_Select_Object')
dynamicOption.xpath = "//option[contains(@value, 'DISPATCH1')]"
WebUI.selectOptionByValue(dynamicOption, 'DISPATCH1', false, 10)
  • Avoid regex for fixed values like JSON strings.
  • Use isRegex: false unless partial/flexible matching is required.

You have selectOptionByValue, which means you have looked at the HTML and your <select> tag has a “value” attribute. Or, do you mean you want to choose the drop-down label. If you want to choose the option that is in the drop-down, you need to use: selectOptionByLabel.

Additionally, as @dineshh mentioned, Katalon Studio “helps” create the selectOption statement in the Manual tab using a default “isRegex” as true. You have to be in control of this. RegEx (Regular Expression) uses pattern matching (example below), not a straight comparison. Use Regex if you know what you are doing, otherwise, set the “isRegex” boolean value to false.

WebUI.selectOptionByLabel(findTestObject('...'), "Monday", false)

or, if you want to use RegEx:

WebUI.selectOptionByLabel(findTestObject('...'), "${gLastDate}\\s\\d{1,2}:\\d{2}:\\d{2}\\s(a|p)m" , true)

Edit: All I wanted was the specific date from the list, and didn’t care about the time. I could have used "${gLastDate} .*" as well.

Edit2: if you do not have a <select> tag like @kazurayam believes, you can still work with it, but not with any of the selectOption statements. Instead, you can take a read of the below and use a parallel to get your drop-down options.