public void Show(bool isMultiple) { CallOnObjectLookUpCalling(); string popupURL = "~/UserControls/LOV/SCG.DB/UserGroupLookUp.aspx?IsMultiple={0}&UserGroupCode={1}&UserGroupName={2}"; ctlUserGroupLookupPopupCaller.URL = string.Format(popupURL, new object[] { isMultiple, UserGroupCode, UserGroupName }); ctlUserGroupLookupPopupCaller.ReferenceValue = IsMultiple.ToString(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), ctlUserGroupLookupPopupCaller.ClientID + "_popup()", ctlUserGroupLookupPopupCaller.ClientID + "_popup('" + ctlUserGroupLookupPopupCaller.ProcessedURL + "')", true); }
/// <summary> /// Entry point to perform operations on the IWebElement selected with the Identifier and filters. /// </summary> /// <param name="extraInfo"> /// For Getter(): specify the kind of information to be retrieved from the Select element. /// If it is null, "" or "textKey": return the textKey of the first selected option, or the textKey of the whole select. /// If it is "index" or "#": then either the "index" attribute valueKey of the Selected option (if it is defined) or /// or the sequence number (from 0) of the Selected option in the Options are returned as a string. /// If it is "valueKey" or "$": the valueKey of the "valueKey" attribute is returned if it is defined, or null if undefined. /// If it is "isMultiple": then "true" or "false" is returned to show if the Select element enable multiple select /// If it is "AllSelected": all selected items are listed with their textKey /// For Setter(): defines which option is to be affected. /// /// </param> /// <param name="filters"></param> /// <returns></returns> public override string this[string extraInfo, Func <IWebElement, bool> filters = null] { get { IWebElement element = FindElement(filters); string resultString; if (string.IsNullOrEmpty(extraInfo)) { resultString = Selected == null?FindElement().Text : Selected.Text; Console.WriteLine("\"{0}\"=[{1}];", resultString, Identifier.FullName()); return(resultString); } switch (extraInfo.ToLowerInvariant()) { case Operation.TextOf: resultString = Selected == null?FindElement().Text : Selected.Text; break; case Operation.IndexOf: case Operation.IndexSign: if (Selected == null) { resultString = "-1"; } else { resultString = Selected.GetAttribute(INDEX); resultString = resultString == null?Options.IndexOf(Selected).ToString() : resultString; } break; case Operation.ValueOf: case Operation.ValueSign: resultString = Selected == null ? null : Selected.GetAttribute("value"); break; case Operation.IsMultiple: resultString = IsMultiple.ToString(); break; case Operation.AllOptions: var optionTexts = Options.Select(e => e.Text); resultString = string.Join(", ", optionTexts); break; case Operation.AllSelected: { var allSelectedText = AllSelected.Select(e => e.Text); resultString = string.Join(", ", allSelectedText); break; } default: return(base[extraInfo, filters]); } Console.WriteLine("\"{0}\"=[{1}, \"{2}\"];", resultString, Identifier.FullName(), extraInfo); return(resultString); } set { IWebElement element = FindElement(filters); string prefix = string.IsNullOrEmpty(extraInfo) ? null : ReservedPrefixes.FirstOrDefault(s => extraInfo.StartsWith(s, StringComparison.InvariantCultureIgnoreCase)); if (prefix == null) { //By default, when "extraInfo" is not specified, SendKeys(valueKey+Tab) to let browser click the target option //Notice: this click would happen no matter if the valueKey is "true" or "false", and it doesn't select multiple options. string keysToBeSend = extraInfo ?? value; //WARNING: Sometime, even when it works in debugging, SendKeys() to multiple // select may fail to select the option foreach (char ch in keysToBeSend) { element.SendKeys(ch.ToString()); Thread.Sleep(100); } element.SendKeys(Keys.Tab); Thread.Sleep(500); Console.WriteLine("[{0}]=\"{1}\";", Identifier.FullName(), keysToBeSend); return; } string key = extraInfo.Substring(prefix.Length); //The valueKey string shall be "True" or "False" to indicate the concerned option shall be selected or deselected bool toSelect = false; if (!bool.TryParse(value, out toSelect)) { //Do nothing if the valueKey is not a boolean valueKey Console.WriteLine("Failed to parse command associated with '{0}'.", value); return; } if (prefix.EndsWith(KEY_PREFIX)) { prefix = prefix.Substring(0, prefix.Length - KEY_PREFIX.Length); } switch (prefix) { case Operation.TextOf: SelectByText(key, toSelect); break; case Operation.IndexOf: case Operation.IndexSign: SelectByIndex(key, toSelect); break; case Operation.ValueOf: case Operation.ValueSign: SelectByValue(key, toSelect); break; case Operation.AllOptions: SelectAll(toSelect); break; } Console.WriteLine("[{0}, \"{1}\"]=\"{2}\";", Identifier.FullName(), extraInfo, value); } }