예제 #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
        public String GetSelectValueById(String id)
        {
            IHTMLSelectElement element = (IHTMLSelectElement)GetElementById(id);
            IHTMLOptionElement option  = element.options[element.selectedIndex];

            return(option.value);
        }
예제 #3
0
        public override bool Parse(ActionBuilder.ActionParameter parameter)
        {
            base.Parse(parameter);

            SelectParameter sp = parameter as SelectParameter;

            ByValue = sp.ByValue;
            var selectedElement = parameter.Element as IHTMLSelectElement;

            if (selectedElement == null)
            {
                return(false);
            }
            //var optionElements = selectedElement.options as mshtml.HTMLSelectElementClass;
            //if (optionElements == null) return false;
            //foreach (IHTMLOptionElement option in selectedElement)
            for (int i = 0; i < selectedElement.length; i++)
            {
                IHTMLOptionElement option = selectedElement.item(i, i) as IHTMLOptionElement;
                if (option.selected)
                {
                    SelectedValue = option.value;
                    SelectedText  = option.text;
                    break;
                }
            }
            return(true);
        }
예제 #4
0
        public void OptionSharesFormOfSelect()
        {
            CQ cq = CQ.Create("<form id=a><select form=b><option></option></select></form><form id=b></form>");
            IHTMLOptionElement option = cq["option"].FirstElement() as IHTMLOptionElement;

            Assert.IsNotNull(option);
            Assert.IsNotNull(option.Form);
            Assert.AreEqual("b", option.Form.Id);
        }
예제 #5
0
        public string GetValueByIndex(int index)
        {
            if (index >= Length || index < 0)
            {
                throw new SUIException("Index is out of range!");
            }

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

            return(option.value);
        }
예제 #6
0
        private void DoSelectChange(object sender, IHTMLEventObj evt)
        {
            IHTMLElement element = evt.srcElement;
            string       locator = LocateDetector.Detect(element);

            IHTMLSelectElement select = element as IHTMLSelectElement;
            IHTMLOptionElement option = IE.Element.GetOption(select, string.Format("index={0}", select.selectedIndex));

            if (null == option)
            {
                return;
            }

            this.OnCommandRecording("select", locator, "label=" + option.text);
        }
예제 #7
0
        /* F  S E T  S E L E C T  C O N T R O L  T E X T */
        /*----------------------------------------------------------------------------
        	%%Function: FSetSelectControlText
        	%%Qualified: ArbWeb.ArbWebControl.FSetSelectControlText
        	%%Contact: rlittle
        	
        ----------------------------------------------------------------------------*/
        static public bool FSetSelectControlTextFromDoc(
            WebControl awc,
            IHTMLDocument2 oDoc2,
            string sName,
            string sid,
            string sValue,
            bool fCheck)
        {
            IHTMLElementCollection hec;

            hec = (IHTMLElementCollection) oDoc2.all.tags("select");
            bool fNeedSave = false;

            foreach (IHTMLSelectElement ihie in hec)
            {
                if (String.Compare(ihie.name, sName, true) == 0)
                {
                    int iIndex;

                    IHTMLElementCollection ihecOptions = (IHTMLElementCollection) ihie.tags("option");
                    for (iIndex = 0; iIndex < ihecOptions.length; iIndex++)

                        //foreach (IHTMLOptionElement ihoe in (IHTMLElementCollection)ihie.tags("option"))
                    {
                        IHTMLOptionElement ihoe = (IHTMLOptionElement) ihecOptions.item(iIndex);

                        if (ihoe.text == sValue)
                        {
                            // value is already set...
                            if (ihie.value == ihoe.value)
                                return false;

                            ihoe.selected = true;
                            DispatchChangeEventCore(awc, sid, "change");
                            // DispatchChangeEventTry2(awc, iIndex, sid, ihie, ihoe, oDoc2);
                            return true;
                        }
                    }
                }
            }

            awc.ReportNavState("never found control for set");
            return fNeedSave;
        }
예제 #8
0
        static void DispatchChangeEventTry2(
            WebControl awc,
            int iIndex,
            string sControl,
            IHTMLSelectElement ihie,
            IHTMLOptionElement ihoe,
            IHTMLDocument2 oDoc2)
        {
            object dummy = null;
            IHTMLDocument4 oDoc4 = (IHTMLDocument4) oDoc2;
            object eventObj = oDoc4.CreateEventObject(ref dummy);
            IHTMLEventObj2 obj2 = (IHTMLEventObj2) eventObj;

            IHTMLElement3 ihe3 = (IHTMLElement3) ihie;
            awc.ResetNav();
            awc.ReportNavState("Before FireEvent");
//            ihe3.FireEvent("onchange", ref eventObj);

            HtmlElement head = awc.AxWeb.Document.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = awc.AxWeb.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement) scriptEl.DomElement;

            // element.text = $"function changeSelect() {{ $'({sControl}').trigger('change'); }}";
            element.text = "function triggerOnChange() "
                           + "{{ "
                           +
//                           "alert('im here'); " +
                           $"var ctl = document.getElementById('{sControl}'); "
                           +
//                           "alert(ctl); "+
                           "var evt = document.createEvent('HTMLEvents'); "
                           + "evt.initEvent('change', false, true); "
                           + "ctl.dispatchEvent(evt);"
                           + "}} ";
            // element.text = $"function triggerOnChange() {{ alert('{sControl}');}}";
            head.AppendChild(scriptEl);

            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.AxWeb.Document.InvokeScript("triggerOnChange");
            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.ReportNavState("After FireEvent");
            awc.WaitForBrowserReady();
            awc.WaitDoLog(500);
        }
예제 #9
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);
        }
예제 #10
0
        public override bool GetPropertyValue(string argProperty, out object argValue)
        {
            argValue = null;
            if (string.Equals(argProperty, UIPropertyKey.s_selectIndexKey, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    IHTMLSelectElement iSelect = QuerySelectInterface();
                    argValue = iSelect.selectedIndex;
                    iSelect  = null;
                }
                catch (System.Exception ex)
                {
                    Log.UIService.LogWarn("Failed to set property value of a select element", ex);
                    return(false);
                }

                return(true);
            }
            else if (string.Equals(argProperty, UIPropertyKey.s_selectTitleKey, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    IHTMLSelectElement iSelect = QuerySelectInterface();
                    IHTMLOptionElement option  = iSelect.options[iSelect.selectedIndex];
                    if (null == option)
                    {
                        iSelect = null;
                        return(false);
                    }

                    argValue = option.text;
                    option   = null;
                    iSelect  = null;
                }
                catch (System.Exception ex)
                {
                    Log.UIService.LogWarn("Failed to set property value of a select element", ex);
                    return(false);
                }

                return(true);
            }
            else if (string.Equals(argProperty, UIPropertyKey.s_selectValueKey, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    IHTMLSelectElement iSelect = QuerySelectInterface();
                    IHTMLOptionElement option  = iSelect.options[iSelect.selectedIndex];
                    if (null == option)
                    {
                        iSelect = null;
                        return(false);
                    }

                    argValue = option.value;
                    option   = null;
                    iSelect  = null;
                }
                catch (System.Exception ex)
                {
                    Log.UIService.LogWarn("Failed to set property value of a select element", ex);
                    return(false);
                }

                return(true);
            }
            else
            {
                return(base.GetPropertyValue(argProperty, out argValue));
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
 public OptionElement(IHTMLOptionElement e, DocumentElement d)
     : base(e as IHTMLElement, d)
 {
 }
예제 #13
0
        static void DispatchChangeEvent(WebControl awc, int iIndex, string sControl, IHTMLSelectElement ihie, IHTMLOptionElement ihoe, IHTMLDocument2 oDoc2)
        {
            ihoe.selected = true;
            object dummy = null;
            IHTMLDocument4 oDoc4 = (IHTMLDocument4)oDoc2;
            object eventObj = oDoc4.CreateEventObject(ref dummy);
            IHTMLEventObj2 obj2 = (IHTMLEventObj2)eventObj;

            IHTMLSelectElement hsec = ihie as IHTMLSelectElement;
            awc.ReportNavState("Before FireEvent");
            hsec.FireEvent("onchange", ref eventObj);
            awc.ReportNavState("After FireEvent");
        }
예제 #14
0
        static void DispatchEventNew(ArbWebControl awc, int iIndex, string sControl, IHTMLSelectElement ihie, IHTMLOptionElement ihoe, IHTMLDocument2 oDoc2)
        {
            ihoe.selected = true;
            object dummy = null;
            IHTMLDocument4 oDoc4 = awc.Document4;
            object eventObj = oDoc4.CreateEventObject(ref dummy);
            var obj = eventObj;
            obj.initEvent("onchange", true, true);

            IHTMLEventObj2 obj2 = (IHTMLEventObj2)eventObj;

            HTMLSelectElementClass hsec = ihie as HTMLSelectElementClass;
            awc.ReportNavState("Before FireEvent");
            hsec.selectedIndex = iIndex;
            
            obj2.fromElement = hsec;
            obj2.srcElement = hsec;
            obj2.propertyName = sControl;

            bool f;
            oDoc4.FireEvent("change", ref eventObj);

            awc.ReportNavState("After FireEvent");
        }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Option"/> class.
 /// </summary>
 /// <param name="ie">The ie.</param>
 /// <param name="optionElement">The option element.</param>
 public Option(DomContainer ie, IHTMLOptionElement optionElement)
     : base(ie, optionElement)
 {
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Option"/> class.
 /// </summary>
 /// <param name="domContainer">The domContainer.</param>
 /// <param name="element">The option element.</param>
 public Option(DomContainer domContainer, IHTMLOptionElement element) :
     base(domContainer, domContainer.NativeBrowser.CreateElement(element))
 {
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Option"/> class.
 /// </summary>
 /// <param name="ie">The ie.</param>
 /// <param name="optionElement">The option element.</param>
 public Option(DomContainer ie, IHTMLOptionElement optionElement)
     : base(ie, optionElement)
 {
 }