I want to get all the options from a hidden select. Select has \"display: none;\" part so I ran into a problem.
It is possible to select elements in firebug with "display: none;" attribute. They will not be outlined on the page, but in the html tree structure.
Then, verify that you found element propertly with firebug
String optn=select[name="fw3k_ad_input_et_type_group"] option[value="0"]
//optn1=select[name="fw3k_ad_input_et_type_group"] option[value="-1"]
//optn2=select[name="fw3k_ad_input_et_type_group"] option[value="16390"]
//optn3=select[name="fw3k_ad_input_et_type_group"] option[value="17605"]
//optn4=select[name="fw3k_ad_input_et_type_group"] option[value="17636"]
then try to use jscript executor (should always work not taking into consideration whether element visible or not)
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x = $(\""+optn+"\");");
stringBuilder.append("return x.text().toString();") ;
String res= (String) js.executeScript(stringBuilder.toString());
Hope this work for you)
The matter is selenium unable to click invisible elements (or interact with invisible elements in other ways). So js should help. I would resolve it in the following way:
String css1="ul>li:last-child>div[id=unos_select_wrap] select[id="_id_fw3k_ad_input_et_type_group"]>option[value='0']";
String css2="ul>li:last-child>div[id=unos_select_wrap] select[id="_id_fw3k_ad_input_et_type_group"]>option[value='-1']";
String css3="ul>li:last-child>div[id=unos_select_wrap] select[id="_id_fw3k_ad_input_et_type_group"]>option[value='16390']";
String css4="ul>li:last-child>div[id=unos_select_wrap] select[id="_id_fw3k_ad_input_et_type_group"]>option[value='17605']";
String css5="ul>li:last-child>div[id=unos_select_wrap] select[id="_id_fw3k_ad_input_et_type_group"]>option[value='17636']";
public void getOptionTextAndPrintIt(String cssSelector){
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x = $(\""+cssSelector+"\");");
stringBuilder.append("return x.text().toString();");
String res= (String) js.executeScript(stringBuilder.toString());
System.out.println(res);
}
public void allOptionValuesDepiction(){
getOptionTextAndPrintIt(css1);
getOptionTextAndPrintIt(css2);
getOptionTextAndPrintIt(css3);
getOptionTextAndPrintIt(css4);
getOptionTextAndPrintIt(css5);
}
Please let me know if something wrong as soon as you check.