コード例 #1
0
ファイル: FillBase.cs プロジェクト: qwdingyu/C-
 protected bool FillSelectElement(IHTMLSelectElement element, FillParameter parameter, string value)
 {
     if (parameter.CanContain && value != null)
     {
         for (int i = 0; i < element.length; i++)
         {
             IHTMLOptionElement option = element.item(i);
             if (option.text != null && option.text.Contains(value))
             {
                 //element.selectedIndex = i;
                 element.options[i].selected = true;
                 this.InvokeOnChange(element as IHTMLElement);
                 return(true);
             }
         }
     }
     else
     {
         for (int i = 0; i < element.length; i++)
         {
             IHTMLOptionElement option = element.item(i);
             if (option.text == value)
             {
                 //element.selectedIndex = i;
                 element.options[i].selected = true;
                 this.InvokeOnChange(element as IHTMLElement);
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #2
0
ファイル: SUIHtmlSelect.cs プロジェクト: weimingtom/SmartUI
        public string GetTextByIndex(int index)
        {
            if (index >= Length || index < 0)
            {
                throw new SUIException("Index is out of range!");
            }

            IHTMLOptionElement option = (IHTMLOptionElement)selectElement.item(index, index);

            return(option.text);
        }
        private static void recordSelectEvent(IHTMLElement element)
        {
            IHTMLSelectElement selectelement = element as IHTMLSelectElement;
            IHTMLElement       selement      = selectelement.item(selectelement.selectedIndex) as IHTMLElement;
            String             value         = selement.innerText;

            if (!String.IsNullOrEmpty(value))
            {
                CognizantITS.sendRecordedObject(element, "selectByVisibleText", "@" + value);
            }
            else
            {
                CognizantITS.sendRecordedObject(element, "selectByIndex", "@" + selectelement.selectedIndex);
            }
        }
コード例 #4
0
        protected override bool ReadyToPaste(PaymentRequest request)
        {
            HTMLDocument doc = request.Document;
            IEnumerator  e   = doc.getElementsByTagName("div").GetEnumerator();

            while (e.MoveNext())
            {
                if (TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower().StartsWith(DOMESTIC_TRANSFER_TEXT))
                {
                    IHTMLSelectElement beneficiaryList = doc.getElementById(BENEFICIARY_LIST) as IHTMLSelectElement;
                    if (beneficiaryList == null || doc.getElementsByName(DAY_FIELD).length == 0)
                    {
                        return(false);
                    }
                    else if (request.PaymentInfo.IsDefinedTransfer == false)
                    {
                        return(beneficiaryList.selectedIndex == 0);
                    }
                    else
                    {
                        String text = TrimHtml((beneficiaryList.item(beneficiaryList.selectedIndex, null) as IHTMLOptionElement).text).ToLower();
                        if (text.EndsWith(TRUSTED_POSTFIX))
                        {
                            text = text.Substring(0, text.IndexOf(TRUSTED_POSTFIX));
                        }
                        else if (text.EndsWith(NORMAL_POSTFIX))
                        {
                            text = text.Substring(0, text.IndexOf(NORMAL_POSTFIX));
                        }
                        return(request.PaymentInfo.DefinedTransferName.ToLower().Equals(text));
                    }
                }
            }

            return(false);
        }
コード例 #5
0
        //private void FillElement(FillParameterKey parameterKey, object elementContainer, String parameterValue)
        //{
        //    this.Wait();
        //    FillParameter fillParameter = elementContainer as FillParameter;
        //    if (fillParameter == null)
        //    {
        //        Hashtable table = elementContainer as Hashtable;
        //        if (table == null)
        //            return;
        //        else if (parameterKey.Type == Matcher.TYPE_RADIO)
        //        {
        //            // 处理radio类型的选择
        //            if (parameterValue != null)
        //                fillParameter = table[parameterValue] as FillParameter;
        //        }
        //        else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型
        //        {
        //            FillCheckBoxGroup(ref parameterValue, table);
        //            return;
        //        }
        //    }
        //    FillElement(fillParameter, ref parameterValue);
        //}

        //下拉框填报:1.如果只有一个选项就选中  2.如果选项有其他而且值没有其他符合项就选中其他
        private bool FillSelectElement(FillParameter parameter, ref string value)
        {
            IHTMLSelectElement element = base.GetElement(parameter, _formIndex) as IHTMLSelectElement;

            if (element == null)
            {
                return(false);
            }
            List <IHTMLOptionElement> listOptions = new List <IHTMLOptionElement>();
            IHTMLOptionElement        otherOption = null;

            //分割参数值,已经填充的参数值从中删掉
            string[] values = value == null ? null : value.Split(PZHFillManager.regularSeparator, StringSplitOptions.RemoveEmptyEntries);
            if (values == null || values.Length < 1)
            {
                return(false);
            }
            List <String> listValues = new List <String>(values);

            for (int i = 0; i < element.length; i++)
            {
                IHTMLOptionElement option = element.item(i);
                if (String.IsNullOrWhiteSpace(option.text))
                {
                    continue;
                }
                listOptions.Add(option);
                if (option.text == "其他")
                {
                    otherOption = option;
                }
                if (parameter.CanContain)
                {
                    String selectedItem = null;
                    foreach (String item in listValues)
                    {
                        if (option.text.Contains(item))
                        {
                            option.selected = true;
                            selectedItem    = item;
                            break;
                        }
                    }
                    if (parameter.CanDelete && !String.IsNullOrEmpty(selectedItem))
                    {
                        listValues.Remove(selectedItem);
                    }
                }
                else
                {
                    if (listValues.Contains(option.text))
                    {
                        option.selected = true;
                        if (parameter.CanDelete)
                        {
                            listValues.Remove(option.text);
                        }
                        value = String.Join(PZHFillManager.regularJoiner, listValues);
                        base.InvokeChange2(element as IHTMLElement);
                        return(true);
                    }
                }
            }
            if (listOptions.Count == 1)
            {
                listOptions[0].selected = true;
                base.InvokeChange2(element as IHTMLElement);
                return(true);
            }
            foreach (IHTMLOptionElement option in listOptions)
            {
                if (option.text == "其他")
                {
                    option.selected = true;
                    base.InvokeChange2(element as IHTMLElement);
                    return(true);
                }
            }
            return(false);
        }
コード例 #6
0
        private void BuildValuesList(IHTMLElement htmlElem)
        {
            String tagName = htmlElem.tagName.ToLower();

            if ("input" == tagName)
            {
                String val = ((IHTMLInputElement)htmlElem).value;
                if (String.IsNullOrEmpty(val))
                {
                    String type = ((IHTMLInputElement)htmlElem).type;
                    if ((type != null) && type.ToLower() == "file")
                    {
                        val = "insert file path here";
                    }
                    else
                    {
                        val = "insert text here";
                    }
                }

                this.values.Add(val);
            }
            else if ("select" == tagName)
            {
                IHTMLSelectElement selectElem = (IHTMLSelectElement)htmlElem;
                int    len        = selectElem.length;
                Object dummyIndex = 0;

                for (int i = 0; i < len; ++i)
                {
                    Object       crntIndex = i;
                    IHTMLElement crntElem  = (IHTMLElement)selectElem.item(crntIndex, dummyIndex);

                    IHTMLOptionElement crntOption = crntElem as IHTMLOptionElement;
                    if (crntOption != null)
                    {
                        if (crntOption.selected)
                        {
                            // I don't know why spaces appears like 0xA0 (no break space).
                            String crntOptionText = crntOption.text;
                            if (crntOptionText != null)
                            {
                                crntOptionText = crntOptionText.Replace('\xA0', '\x20');
                                this.values.Add(crntOptionText);
                            }
                            else
                            {
                                IHTMLOptionElement3 crntOption3 = crntOption as IHTMLOptionElement3;
                                if (crntOption3 != null)
                                {
                                    crntOptionText = crntOption3.label;
                                    if (crntOptionText != null)
                                    {
                                        crntOptionText = crntOptionText.Replace('\xA0', '\x20');
                                        this.values.Add(crntOptionText);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if ("textarea" == tagName)
            {
                String val = ((IHTMLInputElement)htmlElem).value;
                if (String.IsNullOrEmpty(val))
                {
                    val = "insert your text here";
                }

                this.values.Add(val);
            }
        }
コード例 #7
0
        /// <summary>
        /// Checks if any defined transfer is selected on the transfer page.
        /// </summary>
        /// <param name="doc">HTML document</param>
        /// <returns>true if any defined transfer is selected or false otherwise</returns>
        private bool IsAnyTransferSelected(HTMLDocument doc)
        {
            IHTMLSelectElement select = (doc.getElementsByName(DEFINED_TRANSFER_FIELD) as IHTMLElementCollection).item(0, null) as IHTMLSelectElement;

            return(select.selectedIndex == 0 && "wybierz".Equals(TrimHtml((select.item(0, null) as IHTMLOptionElement).text).ToLower()));
        }