public static void SelectComboboxValue(string inputId, string value)
        {
            HTMLSelectElementClass input   = (HTMLSelectElementClass)GetElementById(inputId);
            HTMLElementCollection  options = (HTMLElementCollection)input.options;
            HTMLOptionElement      el      = (HTMLOptionElement)options.namedItem(value);

            if (el != null)
            {
                input.selectedIndex = el.index;
            }
        }
Exemplo n.º 2
0
        public static string Execute(HtmlElement dropdown, string value)
        {
            try
            {
                HTMLSelectElementClass iElement = (HTMLSelectElementClass)dropdown.DomElement;
                iElement.value = value;
            }

            catch (Exception ex)
            {
                return(String.Format("Unable to select value in drop down list: {0}", ex.Message));
            }

            return("A value from list was selected.");
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public void SelectValueByIndex(string inputId, int index)
        {
            HTMLSelectElementClass input = (HTMLSelectElementClass)GetSelectElement(inputId);

            input.selectedIndex = index;
        }
        /// <summary>
        /// Creates a HtmlSelectTag from a HTMLSelectElementClass.
        /// </summary>
        /// <param name="selectElement"> The HTMLSelectElementClass to convert.</param>
        /// <returns> A HtmlSelectTag</returns>
        private HtmlSelectTag CreateHtmlSelectTag(HTMLSelectElementClass selectElement)
        {
            HtmlSelectTag tag = new HtmlSelectTag();

            tag.Class = selectElement.className;
            tag.Id = selectElement.id;
            if ( selectElement.name != null )
            {
                tag.Name = selectElement.name;
            }
            else
            {
                if ( selectElement.id != null )
                {
                    tag.Name = selectElement.id;
                }
                else
                {
                    tag.Name = selectElement.uniqueID;
                    tag.Id = selectElement.uniqueID;
                }
            }
            // TODO: parse from innerHtml
            // tag.OnClick =
            // tag.Style=currentNode.GetAttribute("style",currentNode.NamespaceURI);
            tag.Title = selectElement.title;

            if ( selectElement.multiple )
            {
                tag.Multiple=true;
            }

            tag.Value = selectElement.value;

            // tag.Options = new HtmlOptionCollection();
            //object noll = null;

            IHTMLElementCollection options = (IHTMLElementCollection)selectElement.children;

            // while ( options.MoveNext() )
            foreach ( object obj in options )
            {
                if ( obj is HTMLOptionElementClass )
                {
                    HTMLOptionElementClass option = (HTMLOptionElementClass)obj;

                    HtmlOptionTag optionTag = new HtmlOptionTag();
                    optionTag.Id = option.id;
                    if ( option.selected )
                    {
                        optionTag.Selected=true;
                    }

                    if ( option.text == null )
                    {
                        optionTag.Text = string.Empty;
                    }
                    else
                    {
                        optionTag.Text = option.text;
                    }

                    if ( option.value == null )
                    {
                        optionTag.Value = string.Empty;
                    }
                    else
                    {
                        optionTag.Value = option.value;
                    }

                    optionTag.Key = "Option " + tag.Options.Length.ToString();
                    tag.AddOptionTag(optionTag);
                }
            }

            return tag;
        }
Exemplo n.º 6
0
        public void onfocusout(IHTMLEventObj pEvtObj)
        {
            string log;
            string code = null;

            if (pEvtObj.srcElement is HTMLInputElementClass &&
                !(pEvtObj.srcElement is HTMLButtonElementClass))
            {
                HTMLInputElementClass text = pEvtObj.srcElement as HTMLInputElementClass;
                log = String.Format("Focus Out \"{0}\"", (text.id != null ? text.id     : text.name));
                switch (text.type)
                {
                case "text":
                case "password":
                    if (text.id != null && text.id.Length > 0)
                    {
                        code = watirMaker.SetTextField(":id", text.id, text.value);
                    }
                    else if (text.name != null && text.name.Length > 0)                             //use name
                    {
                        code = watirMaker.SetTextField(":name", text.name, text.value);
                    }
                    break;

                case "checkbox":
                    if (text.id != null && text.id.Length > 0)
                    {
                        code = watirMaker.Checkbox(":id", text.id, text.value);
                    }
                    else if (text.name != null && text.name.Length > 0)                             //use name
                    {
                        code = watirMaker.Checkbox(":name", text.name, text.value);
                    }
                    break;
                }
                formBackpointer.LogEvent(log);
            }
            else if (pEvtObj.srcElement is mshtml.HTMLTextAreaElement)
            {
                HTMLInputElement text = pEvtObj.srcElement as HTMLInputElement;
                switch (text.type)
                {
                case "textarea":
                    if (text.id != null && text.id.Length > 0)
                    {
                        code = watirMaker.SetTextField(":id", text.id, text.value);
                    }
                    else if (text.name != null && text.name.Length > 0)     //use name
                    {
                        code = watirMaker.SetTextField(":name", text.name, text.value);
                    }
                    break;
                }
            }
            else if (pEvtObj.srcElement is HTMLSelectElementClass)
            {
                HTMLSelectElementClass list = pEvtObj.srcElement as HTMLSelectElementClass;
                log = String.Format("Focus Out \"{0}\"", (list.id != null ? list.id     : list.name));
                if (list.id != null && list.id.Length > 0)
                {
                    code = watirMaker.SelectList(":id", list.id, list.value);
                }
                else if (list.name != null && list.name.Length > 0)                 //use name
                {
                    code = watirMaker.SelectList(":name", list.name, list.value);
                }
                formBackpointer.LogEvent(log);
            }
            if (code != null)
            {
                formBackpointer.AppendText(code);
            }
        }