/// <summary> /// Returns the text of all options from a combobox /// </summary> /// <param name="webElement"></param> /// <param name="webElementType"></param> /// <returns>An IEnumerable with text of all options in the combobox</returns> public static IEnumerable <string> GetAllOptionsText(this IWebElement webElement, WebElementType webElementType) { var driver = ((IWrapsDriver)webElement).WrappedDriver; var jsExecutor = (IJavaScriptExecutor)driver; IEnumerable <string> text = null; switch (webElementType) { case WebElementType.HtmlCombo: { var allOptions = new SelectElement(webElement).Options; text = allOptions.Select(option => option.GetText()); break; } case WebElementType.JQueryCombo: { IEnumerable <object> textObjects = (ReadOnlyCollection <object>) jsExecutor.ExecuteScript("var optionTexts = [];" + "var options = arguments[0].options;" + "for(var i = 0; i < options.length; i++)" + "{" + "optionTexts.push(options[i].text);" + "}" + "return optionTexts;", webElement); text = textObjects.Select(x => (string)x).ToList(); break; } } return(text); }
public IReadOnlyList <string> GetAvailableSizes() { var options = new SelectElement(selectListSize).Options; return(options.Select(opt => opt.Text).ToList().AsReadOnly()); }