/// <summary> /// Check the desired string is present in the Dropdown list /// </summary> /// Authour: Vamsi Krishna Boyapati /// <param name="objMySelenium">Selenium RC instance</param> /// <param name="locator">Locator of the Control/Element(Xpath)</param> /// <param name="expectedItem">Expected string </param> /// <returns>Boolean value(True/False)</returns> public bool CheckItemPresentInDropDownList(ISelenium objMySelenium, string locator, string expectedItem) { bool bStatus = false; try { string[] itemArray = objMySelenium.GetSelectOptions(locator); for (int i = 0; i < itemArray.Length; i++) { if (itemArray[i] == expectedItem) { bStatus = true; } } } catch (AutomationException EX) { Console.WriteLine(EX.Message); } return(bStatus); }
/// <summary> /// Method to select item from ComboBox/DropDown /// </summary> /// Authour: Vamsi krishna Boyapati /// <param name="objMySelenium">RC instance</param> /// <param name="strLocator">Locator of the Control/Element(Xpath)</param> /// <param name="itemToSelect">String to select</param> /// <returns>Boolean value(True/False)</returns> public bool SelectItemFromDropDwon(ISelenium objMySelenium, string strLocator, string itemToSelect) { bool bStatus = false; try { string[] arrItems = objMySelenium.GetSelectOptions(strLocator); foreach (string strTemp in arrItems) { if (strTemp.ToUpper().Trim().Contains(itemToSelect.Trim().ToUpper())) { objMySelenium.Select(strLocator, strTemp); bStatus = true; break; } } } catch (AutomationException EX) { Console.WriteLine(EX.Message); } return(bStatus); }
///<summary> /// This method selects avalue from list/combo box /// <example>SelectValueFromListbox(browser, xPath, value)</example> public void SelectValueFromListbox(ISelenium browserObj, string strLocator, string value) { try { CFframeworkCommonObj.PageSync(browserObj); Assert.IsTrue(browserObj.IsVisible(strLocator), strLocator + " element is not present"); string[] itemArray = browserObj.GetSelectOptions(strLocator); for (int i = 0; i < itemArray.Length; i++) { if (itemArray[i].ToLower().Trim() == value.ToLower().Trim()) { browserObj.Select(strLocator, value); CFframeworkCommonObj.PageSync(browserObj); break; } else { if (i == itemArray.Length - 1) { Console.WriteLine(value + " not found in the list box"); Fail(value + " not found in the list box"); } } } } catch (Exception ex) { Console.WriteLine("Function 'SelectValueFromListbox' - Failed"); Console.WriteLine(ex.Message); Fail(ex.Message); } }