I'm trying to create a script that randomly selects an option from a drop-down list.
For that I use a randomly generated number as the index of the set value. The issue is that if it tries to select an item that doesn't exist (like, if the randomly generated number is 6 and the list only has 5 options), the script stops and doesn't run the rest of the code.
So it needs to generate a random integer in the range from 1 to the exact number of options. For now I have hard coded the range in the script, so it works ok in this specific case, but I would like it to work for whatever number of options the drop-down may have, so it continues working if the number of options is changed.
So I would need to get the number of options in the drop-down to set as the maximum value of the range to generate a random number from. But I can't find anywhere a way to get the "size" or "length" of the drop-down options. How do I do that?