示例#1
0
        public void Submit()
        {
            if (node is IHTMLFormElement)
            {
                ((IHTMLFormElement)node).submit();
            }
            else if (node is IHTMLInputElement)
            {
                string type = GetAttribute("type");
                if (type != null && ("submit".Equals(type.ToLower()) || "image".Equals(type.ToLower())))
                {
                    Click();
                }
                else
                {
                    ((IHTMLInputElement)node).form.submit();
                }
            }
            else
            {
                IHTMLFormElement form = FindParentForm();
                if (form == null)
                {
                    throw new NoSuchElementException("Unable to find the containing form");
                }
                form.submit();
            }

            parent.WaitForLoadToComplete();
        }
        /// <summary>
        /// Inserts a new input field
        /// </summary>
        /// <param name="fieldName">The name of the new field</param>
        /// <param name="formName">THe name of the form the field would be added</param>
        /// <param name="type">The type of the field</param>
        public void InsertInputField(string fieldName, string formName, InputFieldType type, string formValue)
        {
            string fieldType = string.Empty;

            switch (type)
            {
            case InputFieldType.Button:
                fieldType = "button";
                break;

            case InputFieldType.Password:
                fieldType = "password";
                break;

            case InputFieldType.Submit:
                fieldType = "submit";
                break;

            case InputFieldType.Text:
                fieldType = "text";
                break;
            }

            IHTMLFormElement form = this.GetElementByName(formName) as IHTMLFormElement;

            (form as IHTMLElement).innerHTML += "<input type=\"" + fieldType +
                                                "\" name=\"" + fieldName + "\" style=\"position: absolute\"" +
                                                "value=\"" + formValue + "\" />";
            MakeInsertedElementMovable();
        }
示例#3
0
 /// <summary>
 /// 内部方法,添加表单域元素
 /// </summary>
 /// <param name="e"></param>
 internal void AppendElement(IHTMLFormElement e)
 {
     if (!myElements.Contains((HTMLElement)e))
     {
         myElements.Add(( HTMLElement )e);
         e.Form = this;
     }
 }
示例#4
0
 void TryFillInBing(string name)
 {
     Thread.Sleep(500);
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
     {
         if (!UpdateTextInput(0, "q", name) && Tries < 6)
         {
             Tries++;
             TryFillInBing(name);
         }
         else
         {
             IHTMLFormElement form = GetForm(0);
             form.submit();
         }
     }));
 }
示例#5
0
        private bool UpdateTextInput(int formId, string name, string text)
        {
            bool             successful = false;
            IHTMLFormElement form       = GetForm(formId);

            if (form != null)
            {
                var element = form.item(name: name);
                if (element != null)
                {
                    var textinput = element as HTMLInputElement;
                    textinput.value = text;
                    successful      = true;
                }
            }

            return(successful);
        }
        /// <summary>
        /// Returns the form data of the provided form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="submitter">The validated submitter element.</param>
        /// <returns>A lazy list of form field data.</returns>
        private static IEnumerable<NameValueType> GetNameValueTypes(IHTMLFormElement form, IDomElement submitter)
        {
            // walk the form fields
            foreach (IDomElement e in form.Document.GetDescendentElements().Where(e => !IsExcludedFromDataSet(form, e, submitter)))
            {
                // TODO: handle dirname
                // TODO: handle file uploads
                // TODO: handle plugin objects
                // TODO: handle keygen

                if (e is IHTMLInputElement && e.Type == "image")
                {
                    string name = e.GetAttribute("name", string.Empty);
                    if (name != string.Empty)
                    {
                        name += ".";
                    }

                    yield return new NameValueType(name + "x", "0", e.Type);
                    yield return new NameValueType(name + "y", "0", e.Type);
                }
                else if (e is IHTMLSelectElement)
                {
                    foreach (NameValueType pair in GetOptionKeyValueTuples(e as IHTMLSelectElement))
                    {
                        yield return pair;
                    }
                }
                else if (e is IHTMLInputElement && (e.Type == "checkbox" || e.Type == "radio"))
                {
                    yield return new NameValueType(e.Name, e.GetAttribute("value", "on"), e.Type);
                }
                else if (e is IHTMLTextAreaElement)
                {
                    // TODO: handle textarea properly
                    yield return new NameValueType(e.Name, WebUtility.HtmlDecode(e.Value), e.Type);
                }
                else
                {
                    yield return new NameValueType(e.Name, e.GetAttribute("value", string.Empty), e.Type);
                }
            }
        }
        /// <summary>
        /// Returns the form data of the provided form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="submitter">The validated submitter element.</param>
        /// <param name="implicitSubmission">
        /// Whether or not to use implicit submission. Implicit submission takes precedence over
        /// the provided submitter.
        /// </param>
        /// <returns>A lazy list of form field data.</returns>
        public static IEnumerable<NameValueType> GetNameValueTypes(IHTMLFormElement form, IDomElement submitter, bool implicitSubmission)
        {
            // ensure the submitter node is valid
            if (submitter != null && !IsValidSubmitter(form, submitter))
            {
                throw new ArgumentException("The provided submitter node is not a button or does not belong to the provided form.");
            }

            // find the first valid submitter if we are doing implicit submission
            if (implicitSubmission)
            {
                submitter = form
                    .Document
                    .GetDescendentElements()
                    .FirstOrDefault(e => IsValidSubmitter(form, e));
            }

            return GetNameValueTypes(form, submitter).ToArray();
        }
        /// <summary>
        /// Determines whether the provided element is a valid submitter of the provided form.
        /// </summary>
        /// <param name="form">The form to test.</param>
        /// <param name="e">The element to test.</param>
        /// <returns>True if the provided element is a valid submitter of the provided for. False otherwise.</returns>
        private static bool IsValidSubmitter(IHTMLFormElement form, IDomElement e)
        {
            var formElement = e as IFormSubmittableElement;
            if (formElement != null)
            {
                return IsButton(e) && formElement.Form == form;
            }

            return false;
        }
        /// <summary>
        /// Determines whether an element is excluded from a form data set.
        /// </summary>
        /// <param name="form"></param>
        /// <param name="e"></param>
        /// <param name="submitter"></param>
        /// <returns></returns>
        private static bool IsExcludedFromDataSet(IHTMLFormElement form, IDomElement e, IDomElement submitter)
        {
            var submittable = e as IFormSubmittableElement;
            if (submittable == null || submittable.Form != form)
            {
                return true;
            }

            return (e.GetAncestors().Any(a => a.NodeName == "DATALIST")) ||
                   (e.Disabled) ||
                   (IsButton(e) && e != submitter) ||
                   (e is IHTMLInputElement && e.Type == "checkbox" && !e.Checked) ||
                   (e is IHTMLInputElement && e.Type == "radio" && !e.Checked) ||
                   (e.Name.IsNullOrEmpty() && !(e is IHTMLInputElement && e.Type == "image")) ||
                   (e.NodeName == "OBJECT");
        }
示例#10
0
        // search input complete
        void Keyboard_Closed(object sender, EventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                // Document 속성 읽기
                Uri    uri  = new Uri(doc.url);
                String host = uri.Host;

                if (host.Contains(naver))
                {
                    //검색어 셋팅
                    IHTMLElement query = doc.getElementsByName("query").item("query", 0);
                    query.setAttribute("value", System.Windows.Clipboard.GetText());

                    //네이버검색버튼 : search_btn
                    doc.getElementById("search_btn").click();
                }
                else if (host.Contains(search_naver))
                {
                    mshtml.IHTMLElementCollection elemColl = null;
                    elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection;

                    foreach (mshtml.IHTMLElement elem in elemColl)
                    {
                        if (elem.getAttribute("class") != null)
                        {
                            if (elem.className == "bt_search spim")
                            {
                                IHTMLElement query = doc.getElementsByName("query").item("query", 0);
                                //검색어 셋팅
                                query.setAttribute("value", System.Windows.Clipboard.GetText());
                                elem.click();
                                break;
                            }
                        }
                    }
                }
                else if (host.Contains(daum) || host.Contains(google))
                {
                    IHTMLElement q = doc.getElementsByName("q").item("q", 0);
                    q.setAttribute("value", System.Windows.Clipboard.GetText());

                    IHTMLFormElement form_google = doc.forms.item(Type.Missing, 0);
                    form_google.submit();
                }

                else
                {
                    System.Windows.MessageBox.Show("naver google daum 쓰세요");
                }
            }
        }
示例#11
0
文件: main.cs 项目: troj-iii/XinChen
        private void RegCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            wb_.DocumentCompleted -= RegCompleted;

            // Input Reg Info.
            IHTMLDocument2   doc  = (IHTMLDocument2)wb_.Document.DomDocument;
            IHTMLFormElement form = doc.forms.item("main");

            IDictionary <string, string> info = GetRegInfo();

            // Account
            {
                IHTMLInputElement accEle = form.item("username");
                accEle.value = info["username"];
            }

            // Pwd
            {
                IHTMLInputElement pwdEle = form.item("password");
                pwdEle.value = info["password"];
                IHTMLInputElement pwdConfirmEle = form.item("password2");
                pwdConfirmEle.value = info["password"];
            }

            // Real Name
            {
                IHTMLInputElement aliasEle = form.item("alias");
                aliasEle.value = info["alias"];
            }

            // PwdSecurityQuestion
            {
                IHTMLSelectElement qEle = form.item("question");
                qEle.selectedIndex = int.Parse(info["question"]);
            }

            // PwdSecurityAnswer
            {
                IHTMLInputElement aEle = form.item("answer");
                aEle.value = info["answer"];
            }

            // Sex
            // Use default value.
            //{
            //    IHTMLSelectElement sexEle = form.item("answer");
            //    sexEle.selectedIndex = int.Parse(info["answer"]);
            //}

            //  CreditCard Pwd
            {
                IHTMLSelectElement aEle = form.item("drpAuthCodea");
                aEle.selectedIndex = int.Parse(info["drpAuthCodea"]);

                IHTMLSelectElement bEle = form.item("drpAuthCodeb");
                bEle.selectedIndex = int.Parse(info["drpAuthCodeb"]);

                IHTMLSelectElement cEle = form.item("drpAuthCodec");
                cEle.selectedIndex = int.Parse(info["drpAuthCodec"]);

                IHTMLSelectElement dEle = form.item("drpAuthCoded");
                dEle.selectedIndex = int.Parse(info["drpAuthCoded"]);
            }

            // BirthDay
            {
                IHTMLSelectElement yearEle = form.item("year11");
                yearEle.selectedIndex = int.Parse(info["year11"]);

                IHTMLSelectElement monthEle = form.item("maoth11");
                monthEle.selectedIndex = int.Parse(info["month11"]);

                IHTMLSelectElement dayEle = form.item("day11");
                dayEle.selectedIndex = int.Parse(info["day11"]);
            }

            // All use default.
            // Nation
            {
                IHTMLInputElement nationEle = form.item("contory");
            }

            // City
            {
                IHTMLInputElement cityEle = form.item("city");
            }
            // KnownWay
            {
                //...
            }
            // Agreement
            {
            }


            // Submit
            {
                IHTMLElement submitEle = form.item("submitBtn");
                submitEle.click();
            }
        }
 /// <summary>
 /// Returns sequence of form field data.
 /// </summary>
 /// <param name="form">The form element.</param>
 /// <param name="submitter">The submitter element.</param>
 /// <param name="implicitSubmission">Whether or not to use implicit submisssion.</param>
 /// <returns>The sequence of form field data.</returns>
 private static IEnumerable<NameValueType> GetNameValueTypes(IHTMLFormElement form, IDomElement submitter, bool implicitSubmission)
 {
     return FormFieldsParser.GetNameValueTypes(form, submitter, implicitSubmission);
 }
示例#13
0
        protected override bool IsConfirmationPage(PaymentRequest request)
        {
            IHTMLFormElement form = request.Document.getElementById("confirm") as IHTMLFormElement;

            return(form != null);
        }
示例#14
0
 public FormElement(IHTMLFormElement e, DocumentElement d)
     : base(e as IHTMLElement, d)
 {
 }
示例#15
0
        void AddAutoHandler(object sender, EventArgs e)
        {
            DialogResult dr = System.Windows.Forms.MessageBox.Show("Para poder agregar el nuevo sitio a 1000Pass.com es necesario que haya ingresado su usuario y clave. Ya lo ha hecho?", "1000pass.com", MessageBoxButtons.YesNo);

            if (dr == System.Windows.Forms.DialogResult.Yes)
            {
                IHTMLDocument3         htmlDoc          = (IHTMLDocument3)ieInstance.Document;
                IHTMLElementCollection possibleElements = htmlDoc.getElementsByTagName("INPUT");
                IHTMLElement           passwordElement  = null;
                IHTMLElement           usernameElement  = null;
                IHTMLElement           enterElement     = null;
                int c = 0;
                foreach (IHTMLElement possibleElement in possibleElements)
                {
                    // Only not empty input type password
                    if (possibleElement.getAttribute("type").ToString().ToUpper() == "PASSWORD" &&
                        !String.IsNullOrEmpty(((IHTMLInputElement)possibleElement).value))
                    {
                        c++;
                        passwordElement = possibleElement;
                    }
                }


                if (c == 1)
                {
                    int cc = 0;
                    IHTMLFormElement form = ((IHTMLInputElement)passwordElement).form;
                    if (form != null)
                    {
                        foreach (IHTMLElement possibleElement in possibleElements)
                        {
                            string type = possibleElement.getAttribute("type").ToString().ToUpper();
                            if (type == "TEXT" || type == "SUBMIT")
                            {
                                IHTMLFormElement possibleForm = ((IHTMLInputElement)possibleElement).form;
                                if (possibleForm.Equals(form))
                                {
                                    if (type == "TEXT")
                                    {
                                        usernameElement = possibleElement;
                                        cc++;
                                    }
                                    else if (type == "SUBMIT")
                                    {
                                        enterElement = possibleElement;
                                        cc++;
                                    }
                                }
                            }
                        }

                        // Enter element may be a button type submit too!
                        if (cc == 1 && enterElement == null)
                        {
                            possibleElements = htmlDoc.getElementsByTagName("BUTTON");
                            foreach (IHTMLElement possibleElement in possibleElements)
                            {
                                string type = possibleElement.getAttribute("type").ToString().ToUpper();
                                if (type == "SUBMIT")
                                {
                                    if (((IHTMLButtonElement)possibleElement).form.Equals(form))
                                    {
                                        enterElement = possibleElement;
                                        cc++;
                                    }
                                }
                            }
                        }


                        if (cc == 2 &&
                            passwordElement != null &&
                            usernameElement != null &&
                            enterElement != null)
                        {
                            this.usernameValue = ((IHTMLInputElement)usernameElement).value;
                            if (String.IsNullOrEmpty(this.usernameValue))
                            {
                                Utils.l(EMPTY_USERNAME);
                                return;
                            }
                            else
                            {
                                this.clickedElement = usernameElement;
                                this.username       = Utils.FindXPath(usernameElement);
                                MarkAsSelected(USERNAME);
                            }


                            this.passwordValue = ((IHTMLInputElement)passwordElement).value;
                            if (String.IsNullOrEmpty(this.passwordValue))
                            {
                                Utils.l(EMPTY_PASSWORD);
                                return;
                            }
                            else
                            {
                                this.clickedElement = passwordElement;
                                this.password       = Utils.FindXPath(passwordElement);
                                MarkAsSelected(PASSWORD);
                            }


                            this.clickedElement = enterElement;
                            this.enter          = Utils.FindXPath(enterElement);
                            MarkAsSelected(ENTER);

                            Send();
                        }
                        else
                        {
                            this.adding = true;

                            this.menuItemAddManual.Visible = false;
                            this.menuItemAddAuto.Visible   = false;

                            this.menuItemUsername.Visible = false;
                            this.menuItemPassword.Visible = false;
                            this.menuItemEnter.Visible    = false;

                            if (usernameElement == null)
                            {
                                this.menuItemUsername.Enabled = true;
                                this.menuItemUsername.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = usernameElement;
                                this.username       = Utils.FindXPath(usernameElement);
                                this.usernameValue  = ((IHTMLInputElement)usernameElement).value;
                                MarkAsSelected(USERNAME);
                            }


                            if (passwordElement == null)
                            {
                                this.menuItemPassword.Enabled = true;
                                this.menuItemPassword.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = passwordElement;
                                this.password       = Utils.FindXPath(passwordElement);
                                this.passwordValue  = ((IHTMLInputElement)passwordElement).value;
                                MarkAsSelected(PASSWORD);
                            }


                            if (enterElement == null)
                            {
                                this.menuItemEnter.Enabled = true;
                                this.menuItemEnter.Visible = true;
                            }
                            else
                            {
                                this.clickedElement = enterElement;
                                this.enter          = Utils.FindXPath(enterElement);
                                MarkAsSelected(ENTER);
                            }


                            Utils.l(@"No podemos encontrar todos los campo en forma automatica. Por favor, agregue los campos restantes en manualmente presionando el boton derecho sobre los elementos que no se pudieron encontrar.");
                        }
                    } // form == null
                }
                else
                {
                    Utils.l(@"Existe mas de un campo de tipo clave en esta pagina. Por favor, agregue los campos en forma manual.");
                }
            }
        }
示例#16
0
 public Form(DomContainer domContainer, IHTMLFormElement htmlFormElement) :
     base(domContainer, domContainer.NativeBrowser.CreateElement(htmlFormElement))
 {
 }