/// <summary> /// Gets the first element in a select element containing the user specified text /// </summary> /// <param name="elem">The select element</param> /// <param name="textToSearchFor">The text you want to check for</param> /// <returns></returns> public static IWebElement SelElem_GetFirstItemContainingText(SelectElement elem, string textToSearchFor) { List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem); IWebElement elemContainingText = null; // If any of the items of the list<string> contain the text, add it to the list = foreach (string itemText in itemTextForAllItems) { if (itemText.Contains(textToSearchFor)) { return(elemContainingText); } } return(elemContainingText); }
/// <summary> /// If any of the items in the select element contain the user specified text, return true, else return false /// </summary> /// <param name="elem">The select element</param> /// <param name="textToSearchFor">The text you want to verify exists in the select element</param> /// <returns></returns> public static bool SelElem_ContainsText(SelectElement elem, string textToSearchFor) { List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem); // If any of the items of the list<string> contain the text , return true foreach (string itemText in itemTextForAllItems) { if (itemText.Contains(textToSearchFor)) { return(true); } } return(false); }
/// <summary> /// Gets the count of items in the select element containing the user specified text /// </summary> /// <param name="elem">The select element</param> /// <param name="textToSearchFor">The text you want to check for</param> /// <returns></returns> public static int SelElem_GetCountOfItemsContainingText(SelectElement elem, string textToSearchFor) { List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem); int countOfItems = 0; // If any of the items of the list<string> contain the text, add it to the list = foreach (string itemText in itemTextForAllItems) { if (itemText.Contains(textToSearchFor)) { countOfItems++; } } return(countOfItems); }
/// <summary> /// Selects the first indexed item in the dropdown that contains the user-specified text /// </summary> /// <param name="elem">The element</param> /// <param name="text">The text to search for</param> /// <returns></returns> public static string SelElem_SelectItemContainingText(SelectElement elem, string text) { List <string> itemStrings = ElemGet.SelElem_ListTextToListString(elem); string selectedString = ""; // For each item's string in the dropdown foreach (string itemString in itemStrings) { // If the string contains the user-specified text, then select it if (itemString.Contains(text)) { elem.SelectByText(itemString); selectedString = itemString; break; } } return(selectedString); }