Get all values ​​from the drop down list

I am trying to find a way to display all values ​​and labels from a drop-down list on a web page. With a shortcut, I could use:

my @labels = $sel->get_select_options('s');

The return value is an array of labels in the drop-down list. However, there is no equivalent method to get all values.

Do you guys know how to do this?

+3
source share
1 answer

In Selenium 1 there is no direct API for this. However, you can try this. Consider <select>as shown below.
<select name="mydropdown" id="optionset">
    <option value="Milk">Fresh Milk</option>
    <option value="Cheese">Old Cheese</option>
    <option value="Bread">Hot Bread</option>
</select>

The following is a snippet in Java for extracting values. You can get the logic from this snippet and implement it in Perl.

int no_of_options = selenium.getSelectOptions ("// select [@ id = 'optionset']"). length
String option_values[] = new String[no_of_options];
for (int i=0;i<no_of_options;i++){
   String value = selenium.getAttribute("//select[@id='optionset']/option["+i+"]/@value");
   option_values[i] = value;
}

, .

+7

All Articles