I’m trying to find a way to get all values and label from drop-down in web page.
With label, I could use:
my @labels = $sel->get_select_options('s');
Return value is array of label in drop-down.
However, there’s no equivalent method for getting all values.
Do you guys know how to do this?
As far as in Selenium 1 there is no direct API for this. However you could try this.
Consider a
<select>like 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>Below is the snippet in Java to retrieve 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; }Hope this helps.