Select Item by value property instead of Text

I may have overlooked smth or act stupid but:
I want to use the select item action to select an item from a dropdown list.
The items look like this:

<option value="1">January</option>

While I know how to select the item when I have the text ‘January’ at hand, I have no idea how to select that very same item if I only have the number ‘1’ available.

I checked the docs for the Select Item Action but haven’t found anything helpful.

Help appreciated! :slight_smile:

Thanks

Hi,

Can you try Inject Js Script activity as the following?

"function(e,v){
var ops = e.options;
for (var i = 0 ; i < ops.length ; i++){
    if (ops[i].value == v){
	ops[i].selected=true;
    }
}
}"

Regards,

1 Like

For the moment I’m bound to use StudioX, so no fancy properties available :slight_smile:

But good to know this type of injection is possible!

not sure about StudioX, but you can try “Click” activity with “simulate click” on the selector with the corresponding value. It works in certain UIs

Edit: nvm, if you said

Thanks, I tried as I think I get the idea, but can’t get it to work, but this likely because of me not knowing enough about … anything in StudioX.
I have a solution which I don’t like tbh which is translating the numbers into the month-string first and then use that in the Select Item action.
What also seemed promising for a few seconds was a switch statement (define a saved value before switching, overwrite it with an appropriate value in each switch branch, use it afterwards for the select item action), but seemingly I can’t use a ‘saved value’ and update it with a new value :frowning:

I would prefer an option that I could set to ‘use text’ or ‘use value’ based on what’s available.

#new-features :slight_smile: