Esempio n. 1
0
        private void JDLogin()
        {
            try
            {
                HTMLDocument doc = myBrowser1.Document.DomDocument as HTMLDocument;

                System.Windows.Forms.HtmlDocument document = this.myBrowser1.Document;

                HTMLInputElementClass input = doc.all.item("loginname", 0) as HTMLInputElementClass;
                input.value = "darkhome";

                HTMLInputElementClass pwd = doc.all.item("nloginpwd", 0) as HTMLInputElementClass;
                pwd.value = "edifier";

                //  myBrowser1.Document.InvokeScript("loginsubmit");
                object obj = this.myBrowser1.Document.All["loginsubmit"].InvokeMember("click");

                //  HTMLFormElementClass form = doc.all.item("formlogin", 0) as HTMLFormElementClass;
                //  form.submit();
                //myBrowser1.Refresh();

                //this.myBrowser1.Navigate("http://item.jd.com/388340.html");



                //myBrowser1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void LoginBrowserSetInputFieldValue(HTMLInputElementClass inputFieldElement, string value)
        {
            inputFieldElement.setAttribute("value", value);

            // Fire events
            RunOnStaThread(() => { LoginBrowserDispatchEvent("change", inputFieldElement.id); });
        }
Esempio n. 3
0
        public void GeAlinkFromFrame()
        {
            IEOperateCore         ieCore   = new IEOperateCore("http://psgis.chinasofti.com/oa/SignOnServlet");
            HTMLInputElementClass userName = ieCore.GetElementByTagName <HTMLInputElementClass>("input").ToList().Find(item => item.name.Equals("userName"));
            HTMLInputElementClass passWord = ieCore.GetElementByTagName <HTMLInputElementClass>("input").ToList().Find(item => item.name.Equals("password"));
            HTMLImgClass          imgLogin = ieCore.GetElementByTagName <HTMLImgClass>("img").ToList().Find(item => item.name.Equals("login_r3_c3"));

            userName.value = string.Empty;
            passWord.value = string.Empty;
            userName.value = "E100086376";
            passWord.value = "Qa20080607";
            imgLogin.click();
            Thread.Sleep(3500);
            ieCore = new IEOperateCore("http://psgis.chinasofti.com/oa/portal");
            HTMLDivElementClass btnPMS = ieCore.GetElementByTagName <HTMLDivElementClass>("div").ToList().Find(item => item.className.Equals("channel app_PMS系统"));

            Thread.Sleep(4000);
            btnPMS.click();
            Thread.Sleep(5000);

            ieCore = new IEOperateCore("http://psgpms.chinasofti.com/main.jsp");


            HTMLFrameElementClass midIframe = ieCore.GetInputElementByID <HTMLFrameElementClass>("ManagerLeftFrame");
        }
Esempio n. 4
0
        public string Execute(WebBrowser browser, HtmlElement btn)
        {
            bool   loadFinished   = false;
            int    counterTimeOut = 500;
            string message;

            try
            {
                browser.DocumentCompleted += delegate { loadFinished = true; };

                HTMLInputElementClass iElement = (HTMLInputElementClass)btn.DomElement;
                iElement.click();

                while (!loadFinished && counterTimeOut > 0)
                {
                    Thread.Sleep(100);
                    Application.DoEvents();
                    counterTimeOut--;
                }

                message = string.Format("Button {0} clicked", btn.InnerHtml.ToString());
            }
            catch (Exception ex)
            {
                message = ex.ToString();
            }

            return(message);
        }
        public static void ClickButton(string buttonId)
        {
            HTMLInputElementClass input = (HTMLInputElementClass)GetElementById(buttonId);

            input.click();
            WaitForComplete();
        }
Esempio n. 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                this.myBrowser1.Navigate("https://passport.jd.com/new/login.aspx?ReturnUrl=http%3A%2F%2Fwww.jd.com%2Fbigimage.aspx%3Fid%3D1015445051");

                HTMLDocument doc = myBrowser1.Document.DomDocument as HTMLDocument;

                System.Windows.Forms.HtmlDocument document = this.myBrowser1.Document;

                HTMLInputElementClass input = doc.all.item("loginname", 0) as HTMLInputElementClass;
                input.value = "flysnoopy1984";

                HTMLInputElementClass pwd = doc.all.item("nloginpwd", 0) as HTMLInputElementClass;
                pwd.value = "Edifier1984";

                //  myBrowser1.Document.InvokeScript("loginsubmit");
                object obj = this.myBrowser1.Document.All["loginsubmit"].InvokeMember("click");

                //  HTMLFormElementClass form = doc.all.item("formlogin", 0) as HTMLFormElementClass;
                //  form.submit();
                //myBrowser1.Refresh();

                //this.myBrowser1.Navigate("http://item.jd.com/388340.html");



                //myBrowser1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void ClickButton(string buttonId)
        {
            isDocumentComplete = false;
            HTMLInputElementClass input = GetInputElement(buttonId);

            input.click();
            WaitForComplete();
        }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="element"></param>
 /// <param name="identifier"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static wxAction GetCheckBox(HtmlElement element, string identifier, string value)
 {
     if (identifier == String.Empty)
     {
         HTMLInputElementClass iElement = element.DomElement as HTMLInputElementClass;
         identifier = "";
     }
     return(new wxActClick("", identifier, value, ClickableType.Check));
 }
        public string GetInputValue(string inputId)
        {
            HTMLInputElementClass input = GetInputElement(inputId);

            if (input == null)
            {
                return(null);
            }

            return(input.value);
        }
Esempio n. 10
0
        public void RefreshTestNew()
        {
            IEOperateCore ieCore = new IEOperateCore("www.baidu.com");
            //ieCore.Refresh();
            HTMLInputElementClass searchTextBox = ieCore.GetInputElementByID <HTMLInputElementClass>("kw");

            searchTextBox.value = "China";
            HTMLInputElementClass searchButton = ieCore.GetInputElementByID <HTMLInputElementClass>("su");

            searchButton.click();
        }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="element"></param>
 /// <param name="identifier"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static wxAction GetRadio(HtmlElement element, string identifier, string value)
 {
     if (identifier == String.Empty)
     {
         HTMLInputElementClass iElement = element.DomElement as HTMLInputElementClass;
         //if (iElement != null)
         //    isChecked = iElement.IHTMLOptionButtonElement_status;
         //else
         //    isChecked = false; // TODO Does this make sense?
     }
     return(new wxActClick("Radio", identifier, value, ClickableType.Radio));
 }
Esempio n. 12
0
 public O2FormInputField(HtmlElement heForm_InputField)
 {
     //String asd = heForm_InputField.DomElement.GetType().FullName;
     if (heForm_InputField.DomElement.GetType().FullName == "mshtml.HTMLInputElementClass")
     {
         hieForm_InputField = (HTMLInputElementClass) heForm_InputField.DomElement;
     }
     else
     {
         DI.log.error("in O2FormInputField(), provided object was not a Input Form element: {0}",
                         heForm_InputField.DomElement.GetType().FullName);
     }
 }
        public void SetCheckboxValue(string checkboxId, bool isChecked, bool failIfNotExist)
        {
            HTMLInputElementClass input = GetInputElement(checkboxId);

            if (input == null && failIfNotExist)
            {
                throw new ApplicationException("CheckBox ID: " + checkboxId + " was not found.");
            }
            if (input != null)
            {
                input.@checked = isChecked;
            }
        }
Esempio n. 14
0
 public O2FormInputField(HtmlElement heForm_InputField)
 {
     //String asd = heForm_InputField.DomElement.GetType().FullName;
     if (heForm_InputField.DomElement.GetType().FullName == "mshtml.HTMLInputElementClass")
     {
         hieForm_InputField = (HTMLInputElementClass)heForm_InputField.DomElement;
     }
     else
     {
         DI.log.error("in O2FormInputField(), provided object was not a Input Form element: {0}",
                      heForm_InputField.DomElement.GetType().FullName);
     }
 }
Esempio n. 15
0
        public static string Execute(HtmlElement radioToSelect)
        {
            try
            {
                HTMLInputElementClass iElement = (HTMLInputElementClass)radioToSelect.DomElement;
                iElement.@checked = true;
            }
            catch (Exception ex)
            {
                return(String.Format("Unable to check radio button: {0}", ex.Message));
            }

            return("Radio button was select.");
        }
Esempio n. 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="element"></param>
 /// <param name="identifier"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static wxAction GetButton(HtmlElement element, string identifier, string value)
 {
     if (identifier == String.Empty)
     {
         HTMLInputElementClass iElement = element.DomElement as HTMLInputElementClass;
         if (iElement.src != null)
         {
             identifier = "src";
             value      = iElement.src;
         }
         else
         {
             return(null); // we give up: no name, nor id nor src
         }
     }
     return(new wxActClick("Capt Button", identifier, value, ClickableType.Button));
 }
Esempio n. 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputElement"></param>
        /// <param name="identifier"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static wxAction GetText(HtmlElement inputElement, string identifier, string value)
        {
            int a = 1;
            HTMLInputElementClass iElement = inputElement.DomElement as HTMLInputElementClass;

            if (iElement.type == "hidden")
            {
                return(null);
            }
            if (iElement.readOnly == true)
            {
                a = 2;
            }
            string valueToSet = String.Empty;

            if (iElement.IHTMLInputElement_value != null)
            {
                valueToSet = iElement.IHTMLInputElement_value;
            }
            return(new wxActText("", identifier, value, valueToSet));
        }
Esempio n. 18
0
        public void Open360WebSite()
        {
            IEOperateCore ieCore = new IEOperateCore();

            ieCore.OpenInternetExplorer("https://hao.360.cn");

            HTMLInputElementClass searchTextBox = ieCore.GetInputElementByID <HTMLInputElementClass>("search-kw");


            //searchTextBox.setActive();
            searchTextBox.value = "China";
            //searchTextBox.select();
            //ieCore.SenKey(KeyBoard.Backspace);
            //ieCore.SenKey(KeyBoard.Enter);


            HTMLButtonElementClass searchButton = ieCore.GetInputElementByID <HTMLButtonElementClass>("search-btn");

            searchButton.click();
            //searchButton.FireEvent("click");
            // ieCore.CloseInternetExplorer();
        }
        public void SetInputFileValue(string inputId, string elementValue)
        {
            HTMLDocument          document = ((HTMLDocument)IE.Document);
            HTMLInputElementClass element  = (HTMLInputElementClass)document.getElementById(inputId);

            int nullElementCount = 0;

            // The following loop is to account for any latency that IE
            // might experience.   Tweak the number of times to attempt
            // to continue checking the document before giving up.
            while (element == null && nullElementCount < 10)
            {
                Thread.Sleep(500);
                element = (HTMLInputElementClass)document.getElementById(inputId);
                nullElementCount++;
            }
            element.focus();
            isDocumentComplete = false;
            SendKeys.Send(" ");
            WaitForComplete100();
            SendKeys.Send(elementValue);
            SendKeys.Send("{ENTER}");
        }
        public void SetInputStringValue(string inputId, string elementValue)
        {
            HTMLInputElementClass input = GetInputElement(inputId);

            input.value = elementValue;
        }
Esempio n. 21
0
        public bool onclick(IHTMLEventObj pEvtObj)
        {
            string code = null;

            if (pEvtObj.srcElement is HTMLAnchorElementClass)
            {
                HTMLAnchorElementClass a = (HTMLAnchorElementClass)pEvtObj.srcElement;
                if (string.IsNullOrEmpty(a.id) == false)
                {
                    code = watirMaker.ClickLink(":id", a.id);
                }
                else if (string.IsNullOrEmpty(a.name) == false)
                {
                    code = watirMaker.ClickLink(":name", a.name);
                }
                else if (string.IsNullOrEmpty(a.innerText) == false)
                {
                    code = watirMaker.ClickLink(":text", a.innerText);
                }
                else
                {
                    code = watirMaker.ClickLink(":url", a.href);
                }
            }
            else if (pEvtObj.srcElement is HTMLButtonElementClass)
            {
                HTMLButtonElementClass b = pEvtObj.srcElement as HTMLButtonElementClass;
                if (b.id != null && b.id.Length > 0)
                {
                    code = watirMaker.ClickButton(":id", b.id, b.value);
                }
                else                 //use name or value
                {
                    code = watirMaker.ClickButton(":name", b.name, b.value);
                }
            }
            else if (pEvtObj.srcElement is HTMLInputElementClass)
            {
                HTMLInputElementClass text = pEvtObj.srcElement as HTMLInputElementClass;
                string log = String.Format("Focus Out \"{0}\"", (text.id != null ? text.id      : text.name));
                switch (text.type)
                {
                case "radio":
                    if (text.id != null && text.id.Length > 0)
                    {
                        code = watirMaker.Radio(":id", text.id, text.value);
                    }
                    else if (text.name != null && text.name.Length > 0)                             //use name
                    {
                        code = watirMaker.Radio(":name", text.name, text.value);
                    }
                    break;

                case "submit":
                case "button":
                case "image":
                    if (text.id != null && text.id.Length > 0)
                    {
                        code = watirMaker.ClickButton(":id", text.id, text.value);
                    }
                    else                             //use name or value
                    {
                        code = watirMaker.ClickButton(":name", text.name, text.value);
                    }
                    break;
                }
                formBackpointer.LogEvent(log);
            }
            if (code != null)
            {
                formBackpointer.SuppressOneGoto();
                formBackpointer.AppendText(code);
            }
            return(true);
        }
Esempio n. 22
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);
            }
        }
Esempio n. 23
0
        private void button1_Click(object sender, EventArgs e)
        {
            ////// Create a new instance of the Firefox driver.

            ////// Notice that the remainder of the code relies on the interface,
            ////// not the implementation.

            ////// Further note that other drivers (InternetExplorerDriver,
            ////// ChromeDriver, etc.) will require further configuration
            ////// before this example will work. See the wiki pages for the
            ////// individual drivers at http://code.google.com/p/selenium/wiki
            ////// for further information.
            ////IWebDriver driver = new FirefoxDriver();

            //////Notice navigation is slightly different than the Java version
            //////This is because 'get' is a keyword in C#
            ////driver.Navigate().GoToUrl("http://www.google.com/");

            ////// Find the text input element by its name
            ////IWebElement query = driver.FindElement(By.Name("q"));

            ////// Enter something to search for
            ////query.SendKeys("Cheese");

            ////// Now submit the form. WebDriver will find the form for us from the element
            ////query.Submit();

            ////// Google's search is rendered dynamically with JavaScript.
            ////// Wait for the page to load, timeout after 10 seconds
            ////WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            ////wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });

            ////// Should see: "Cheese - Google Search"
            ////System.Console.WriteLine("Page title is: " + driver.Title);

            //////Close the browser
            ////driver.Quit();
            //string IELocation = @"%ProgramFiles%\Internet Explorer\iexplore.exe";
            //IELocation = System.Environment.ExpandEnvironmentVariables(IELocation);

            //Console.WriteLine("Launching IE ");
            //Process p = Process.Start(IELocation, @"http://www.baidu.com");
            //Thread.Sleep(3000);

            //Console.WriteLine("Attaching to IE ... ");
            //InternetExplorer ie = null;

            //string ieWindowName = "空白页";
            //if (p != null)
            //{
            //    //Console.WriteLine("Process handle is: " + p.MainWindowHandle.ToString());
            //    SHDocVw.ShellWindows allBrowsers = new ShellWindowsClass();
            //    Console.WriteLine("Number of active IEs :" + allBrowsers.Count.ToString());
            //    if (allBrowsers.Count != 0)
            //    {
            //        SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
            //        foreach (SHDocVw.InternetExplorer ieVW in shellWindows)
            //        {
            //            // 判斷視窗是否為 iexplore
            //            if (Path.GetFileNameWithoutExtension(ieVW.FullName).ToLower().Equals("iexplore"))
            //            {
            //                ie = ieVW;
            //                break;
            //            }
            //        }


            //        //for (int i = 0; i < allBrowsers.Count; i++)
            //        //{
            //        //    //IWebBrowser2 iwb2 = allBrowsers.Item(i) as IWebBrowser2;

            //        //    InternetExplorer eitem = (InternetExplorer)allBrowsers.Item(i);
            //        //    int l = eitem.HWND;
            //        //    int j = 0;
            //        //    j++;
            //        //    if (eitem.HWND == (int)p.MainWindowHandle.ToInt32())
            //        //    {
            //        //        ie = eitem;
            //        //        break;
            //        //    }
            //        //}
            //    }
            //    else
            //        throw new Exception("Faul to find IE");
            //}
            //else
            //    throw new Exception("Fail to launch IE");

            ////var ie = new SHDocVw.InternetExplorer();
            ////ie.Visible = true;
            ////object o = null;
            ////Console.WriteLine("打开百度首页...");
            ////ie.Navigate(@"http://www.baidu.com", ref o, ref o, ref o, ref o);
            //Thread.Sleep(1000);

            //HTMLDocument doc = (HTMLDocument)ie.Document;

            //Console.WriteLine("网站标题:" + doc.title);

            //Console.WriteLine("输入搜索关键字:飞苔博客");
            //var keyEle = doc.getElementById("kw");
            //keyEle.setAttribute("value", "飞苔博客", 0);

            //Console.WriteLine("点击[百度一下]按钮,进行搜索");
            //var btnSubmit = doc.getElementById("su");
            //btnSubmit.click();
            //Thread.Sleep(500);

            //Console.WriteLine("网站标题:" + doc.title);
            ////var relatedSearchResultEle = doc.getElementsByTagName("SPAN").Cast<ihtmlelement>().Where(ele => ele.className == "nums").FirstOrDefault();
            //Console.WriteLine("百度相关搜索结果:");
            //p.Close();
            ////Console.WriteLine(relatedSearchResultEle.innerHTML);
            object o = null;

            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();

            SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)ie;
            wb.Visible    = true;
            wb.FullScreen = true;
            //Do anything else with the window here that you wish
            wb.Navigate("http://www.taobao.com/", ref o, ref o, ref o, ref o);
            while (wb.Busy)
            {
                Thread.Sleep(100);
            }
            HTMLDocument          document = ((HTMLDocument)wb.Document);
            IHTMLElement          element  = document.getElementById("q");
            HTMLInputElementClass email    = (HTMLInputElementClass)element;

            email.value = "包装盒子";

            var elements = document.getElementsByTagName("button");

            foreach (HTMLButtonElementClass element1 in elements)
            {
                // If there's more than one button, you can check the
                //element.InnerHTML to see if it's the one you want
                if (element1.innerHTML.Contains("搜 索"))
                {
                    element1.click();
                }
            }
            //for (int i = 0; i < count; i++)
            //{

            //    //去抓標籤名字有a的,像是連結<a href=xx>這種

            //    //奇怪的是這個方法如果要抓一些標籤都抓不到,像是<td><tr>那些=.=

            //    //所以那些我是用另外的方法抓的,等下會講
            //    if (document.all[i].TagName.ToLower().Equals("button"))
            //    {

            //        //GetAttribute就是去取得標籤的屬性的內容,例:

            //        //<a href ="我是屬性的內容" target=_blank>,不過有些屬性取不到,像是class

            //        if (doc.All[i].GetAttribute("type").Contains("submit"))
            //        {                             //InnerText就是取得標籤中間的內容,<標籤>內容</標籤>
            //            //richTextContent1.AppendText(doc.All[i].InnerText);
            //            //richTextContent1.AppendText(doc.All[i].GetAttribute("href"));
            //            //richTextContent1.AppendText(Environment.NewLine);

            //            ////另外這個函式可以去更改HTML裡面屬性的內容
            //            //XXX.SetAttribute("value", "Hello");
            //            int j = i;
            //            j++;
            //        }
            //    }
            //}
            IHTMLElement           search    = document.getElementById(@"tag:BUTTON&value:搜 索");
            HTMLButtonElementClass searchEle = (HTMLButtonElementClass)search;

            searchEle.click();
            //email = null;
            //element = document.getElementById("Passwd");
            //HTMLInputElementClass pass = (HTMLInputElementClass)element;
            //pass.value = "pass";
            //pass = null;
            //element = document.getElementById("signIn");
            //HTMLInputElementClass subm = (HTMLInputElementClass)element;
            //subm.click();
            //subm = null;
            //while (wb.Busy) { Thread.Sleep(100); }
            //wb.Navigate("https://adwords.google.co.uk/o/Targeting/Explorer?", ref o, ref o, ref o, ref o);
            //while (wb.Busy) { Thread.Sleep(100); }
            //string connString = "SERVER=localhost;" +
            //        "DATABASE=test;" +
            //        "UID=root;";

            ////create your mySQL connection
            //MySqlConnection cnMySQL = new MySqlConnection(connString);
            ////create your mySql command object
            //MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
            ////create your mySQL reeader object
            //MySqlDataReader reader;
            ////open the mySQL connection
            //cnMySQL.Open();
            //int j = 1;
            //cmdMySQL.CommandText = "SELECT * FROM `emails1` WHERE `send`>'" + j + "' order by `send` asc limit 0,1";
            //reader = cmdMySQL.ExecuteReader();
            //reader.Read();
            //j = (int)reader.GetValue(1);
            HTMLElementCollection col = default(HTMLElementCollection);

            document = ((HTMLDocument)wb.Document);
            col      = (HTMLElementCollection)document.getElementsByTagName("textarea");
            //the error happens here in this typecast


            //Console.WriteLine(j);
            wb.Quit();
        }
        public void SetInputIntValue(string inputId, int elementValue)
        {
            HTMLInputElementClass input = GetInputElement(inputId);

            input.value = elementValue.ToString();
        }
        /// <summary>
        /// Creates a HtmlInputTag from a HTMLInputElementClass.
        /// </summary>
        /// <param name="inputElement"> The HTMLInputElementClass to convert.</param>
        /// <returns> A HtmlInputTag.</returns>
        private HtmlInputTag CreateHtmlInputTag(HTMLInputElementClass inputElement)
        {
            HtmlInputTag input = new HtmlInputTag();

            input.Checked = [email protected]();
            input.Class = inputElement.className;
            input.Id = inputElement.id;
            input.MaxLength = inputElement.maxLength.ToString();
            if ( inputElement.name != null )
            {
                input.Name = inputElement.name;
            }
            else
            {
                if ( inputElement.id != null )
                {
                    input.Name = inputElement.id;
                }
                else
                {
                    input.Name = inputElement.uniqueID;
                    input.Id = inputElement.uniqueID;
                }
            }
            // input.OnClick = currentNode.GetAttribute("onclick",currentNode.NamespaceURI);
            input.ReadOnly = inputElement.readOnly.ToString();
            //input.Style = currentNode.GetAttribute("style",currentNode.NamespaceURI);
            input.Title = inputElement.title;
            input.Value = inputElement.value;

            switch ( inputElement.type )
            {
                case "button":
                    input.Type=HtmlInputType.Button;
                    break;
                case "checkbox":
                    input.Type=HtmlInputType.Checkbox;
                    break;
                case "file":
                    input.Type=HtmlInputType.File;
                    break;
                case "hidden":
                    input.Type=HtmlInputType.Hidden;
                    break;
                case "image":
                    input.Type=HtmlInputType.Image;
                    break;
                case "password":
                    input.Type=HtmlInputType.Password;
                    break;
                case "radio":
                    input.Type=HtmlInputType.Radio;
                    break;
                case "reset":
                    input.Type=HtmlInputType.Reset;
                    break;
                case "submit":
                    input.Type=HtmlInputType.Submit;
                    break;
                case "text":
                    input.Type=HtmlInputType.Text;
                    break;
                default:
                    input.Type=HtmlInputType.Text;
                    break;
            }

            return input;
        }
Esempio n. 26
0
        private void WebBrowserLogin()
        {
            Debug.WriteLine("Login URL\r\n\r\n{0}\r\n", (object)_loginBrowserHtmlDocument.location.href);

            // Wait for login.live.com page
            Debug.WriteLine("Waiting for host to switch to login.live.com");
            bool success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => {
                try {
                    return
                    (_loginBrowserHtmlDocument.location.host.EndsWith("login.live.com") &&
                     _loginBrowserHtmlDocument.location.pathname.StartsWith("/oauth20_authorize.srf"));
                } catch (Exception) {
                    return(false);
                }
            });

            if (!success)
            {
                throw new LoginException("Failed waiting for login.live.com login page");
            }

            // Wait for login page to load
            Debug.WriteLine("Wait until login.live.com login page is loaded");
            success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => _loginBrowserHtmlDocument.readyState == "complete");
            if (!success)
            {
                throw new LoginException("Unable to load the login.live.com login page");
            }

            IHTMLElementCollection passwdElementCollection = null;

            success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => {
                passwdElementCollection = _loginBrowserHtmlDocument.getElementsByName("passwd");
                return(passwdElementCollection.length == 1);
            });

            if (!success)
            {
                throw new LoginException("Unable to get password field element");
            }

            // Get the login page elements
            Debug.WriteLine("Get the login page elements");
            HTMLInputElementClass passwordInputElement = null;
            HTMLInputElementClass signInButtonElement  = null;

            success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => {
                passwordInputElement = (HTMLInputElementClass)((IHTMLElementCollection3)passwdElementCollection).namedItem("passwd");
                signInButtonElement  = (HTMLInputElementClass)_loginBrowserHtmlDocument.getElementById("idSIButton9");

                return(passwdElementCollection != null && signInButtonElement != null);
            });

            if (!success)
            {
                throw new LoginException("Unable to get login form elements");
            }

            // Update password
            LoginBrowserSetInputFieldValue(passwordInputElement, _password);

            // Click Sign In button
            Debug.WriteLine("Click Sign In button");
            signInButtonElement.click();
        }
        private static void SetInputValue(string inputId, string elementValue)
        {
            HTMLInputElementClass input = (HTMLInputElementClass)GetElementById(inputId);

            input.value = elementValue;
        }