3 Replies Last post: Aug 25, 2008 12:42 AM by Tarun  
Tarun Master 380 posts since
Apr 28, 2008
Currently Being Moderated

Aug 21, 2008 11:38 PM

Extracting values from Drop down list

I was expecting it to be mush easier but it didn't turn out to be.

I had zeroed in on getSelectedLabels method to retrieve values from a drop down but it always happned to return only first value and not whole set of values of drop down list.

 

I got it done by evaluating java script as following -

 

*******************************************************************************************************************************************

String script = "var optionElements = new Array();";
        script += "var links = window.document.getElementsByTagName('form')[0].getElementsByTagName('select')[1].length;";
        script += "for(var i=0; i<links; i++)";
        script += "optionElements[i] = window.document.getElementsByTagName('form')[0].getElementsByTagName('select')[1][i].innerHTML;";
        script += "optionElements.toString();";
        String optionElements = selenium.getEval(script);

 

*******************************************************************************************************************************************

 

I would be willing to know if there is another approcah to do this.

 

Regards,

Tarun K

NLord Pro 96 posts since
Mar 25, 2008
Currently Being Moderated
1. Aug 22, 2008 6:57 AM in response to: Tarun
Re: Extracting values from Drop down list

Probably I haven't got the point, but why don't you use selenium.getSelectOptions() ?

Haroon Advanced 66 posts since
Apr 23, 2008
Currently Being Moderated
2. Aug 22, 2008 9:21 AM in response to: NLord
Re: Extracting values from Drop down list

You can use the following XPath expression to get all the available items from the combo list.

 

id('select')/descendant::*

 

-Haroon

More Like This

  • Retrieving data ...