selectOptionByValue with Regex not finding option

I am writing a test that needs to select from a pull-down list. The list contains options such as:

vpc-123 | Default VPC
vpc-456 | Lab VPC

I wish to select the option that contains “Lab VPC”, but the prefix will be different every time. Thus, I wish to use the regex capability of selectOptionByValue.

My code snippet is:

WebUI.click(findTestObject(‘xxx/Select-LabVPC’))

WebUI.selectOptionByValue(findTestObject(‘xxx/Select-LabVPC’), ‘Lab VPC’, true)

The click is successful, but it never finds the correct option.

The log output is:

05-07-2018 03:04:25 PM - [START] - Start action : selectOptionByValue

05-07-2018 03:04:29 PM - [INFO] - Finding Test Object with id ‘xxx/Select-LabVPC’

05-07-2018 03:04:29 PM - [INFO] - Checking object

05-07-2018 03:04:29 PM - [INFO] - Checking value parameter

05-07-2018 03:04:29 PM - [INFO] - Checking timeout

05-07-2018 03:04:29 PM - [INFO] - Finding web element with id: ‘xxx/Select-LabVPC’ located by ‘By.xpath: //*[contains(text(),‘Lab VPC’)]/…’ in ‘30’ second(s)

05-07-2018 03:04:29 PM - [INFO] - Found 1 web elements with id: ‘xxx/Select-LabVPC’ located by ‘By.xpath: //*[contains(text(),‘Lab VPC’)]/…’ in ‘30’ second(s)

05-07-2018 03:04:29 PM - [INFO] - Selecting options on object ‘xxx/Select-LabVPC’ with value ‘Lab VPC’ using regular expression

05-07-2018 03:04:30 PM - [FAILED] - No option matched.

05-07-2018 03:04:30 PM - [END] - End action : selectOptionByValue

I have been unable to find any examples with isRegex set to true.

I have also tried ‘.*Lab VPC.*’, but it does not match.

What format should be used to match a Regex?

This may help:

Update:

Aha! I’ve been looking for options by their displayed text value, but I now realise that _selectOptionByValue _looks for the [value=“xxx”] value.

My HTML is:

vpc-4a4a6233 | Lab VPC vpc-33f5fe51 | DEFAULT-VPC (default)

So, my challenge is to select the option with “Lab VPC” in the inner text, without relying on the value.

So, do I have to use a selectOption command to click the option, or can I just use a normal click command referring to the option via an xpath reference?

Aha! I got it working by using selectOptionByLabel, and an expression of: ‘.*Lab VPC.*’

Thank you!

John Rotenstein said:

Aha! I got it working by using selectOptionByLabel, and an expression of: ‘.*Lab VPC.*’

Thank you!

Hi John, I’m facing same issue but is not working… can you help me?

WebUI.selectOptionByLabel(findTestObject(‘Pages/User/elListaPerfiles’), ‘.*MESA.*’, true)

How did you do?
Thanks!
Martín