Example #1
0
 public override void SetValue(HtmlElement element)
 {
     // 如果checkbox的有属性是“checked”它将被检查。
     if (Checked)
     {
         element.SetAttribute("checked", "checked");
     }
     else
     {
         element.SetAttribute("checked", null);
     }
 }
        private static void AppendJsElement(this WebBrowser wb, string id, string content)
        {
            HtmlElement JSElement = wb.Document.GetElementById(id);

            if (JSElement == null)
            {
                JSElement = wb.Document.CreateElement("script");
                JSElement.SetAttribute("type", "text/javascript");
                JSElement.SetAttribute("id", id);
                JSElement.SetAttribute("text", content);
                wb.Document.Body.AppendChild(JSElement);
            }
        }
Example #3
0
 public static void SetElementValue(HtmlElement htmlElement, string value)
 {
     if (htmlElement != null)
     {
         htmlElement.SetAttribute("value", value);
     }
 }
Example #4
0
    public void Html(string value, Label label, System.Windows.Forms.HtmlElement html)
    {
        // BAD
        label.Text = Encode(value);
        label.Text = HttpUtility.UrlEncode(value);
        label.Text = HttpUtility.UrlEncode(HttpUtility.HtmlEncode(value));
        var encodedValue = HttpUtility.UrlEncode(value);

        html.SetAttribute("a", encodedValue);
        label.Text = "<img src=\"" + encodedValue + "\" />";
        label.Text = string.Format("<img src=\"{0}\" />", encodedValue);

        // GOOD
        label.Text   = HttpUtility.HtmlEncode(value);
        label.Text   = HttpUtility.HtmlEncode(HttpUtility.UrlEncode(value));
        encodedValue = HttpUtility.HtmlAttributeEncode(encodedValue);
        html.SetAttribute("a", encodedValue);
        label.Text   = "<img src=\"" + encodedValue + "\" />";
        label.Text   = string.Format("<img src=\"{0}\" />", encodedValue);
        encodedValue = HttpUtility.HtmlEncode(encodedValue);
        html.SetAttribute("a", encodedValue);
        label.Text = "<img src=\"" + encodedValue + "\" />";
        label.Text = string.Format("<img src=\"{0}\" />", encodedValue);
    }
Example #5
0
        // DocumentCompleted event handle
        void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = ((WebBrowser)sender).Document;

            ieBrowser.DocumentCompleted -= IEBrowser_DocumentCompleted;

            System.Windows.Forms.HtmlElement search = ieBrowser.Document.GetElementById("name1");
            if (search != null)
            {
                search.SetAttribute("value", "verinon");
                System.Windows.Forms.HtmlElement searchButton = ieBrowser.Document.GetElementById("checkCompanyName_0");

                searchButton.InvokeMember("click");

                ieBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(IEBrowser_DocumentCompleted1);
            }
        }
Example #6
0
        void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = ((WebBrowser)sender).Document;

            ieBrowser.DocumentCompleted -= IEBrowser_DocumentCompleted;

            //System.Windows.Forms.HtmlElement cntrlEnail = ieBrowser.Document.GetElementById("login-email");
            //System.Windows.Forms.HtmlElement cntrlPassword = ieBrowser.Document.GetElementById("login-password");
            //System.Windows.Forms.HtmlElement cntrlSubmit = ieBrowser.Document.GetElementById("login-submit");

            System.Windows.Forms.HtmlElement cntrlEnail    = ieBrowser.Document.GetElementById("session_key-login");
            System.Windows.Forms.HtmlElement cntrlPassword = ieBrowser.Document.GetElementById("session_password-login");
            System.Windows.Forms.HtmlElement cntrlSubmit   = ieBrowser.Document.GetElementById("btn-primary");


            if (cntrlEnail != null && cntrlPassword != null && cntrlSubmit != null)
            {
                cntrlEnail.SetAttribute("value", "*****@*****.**");
                cntrlPassword.SetAttribute("value", "kareti1024");
                cntrlSubmit.InvokeMember("click");

                ieBrowser.DocumentCompleted += IeBrowser_DocumentCompleted;
            }
        }
Example #7
0
        private void IeBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            ieBrowser.DocumentCompleted -= IeBrowser_DocumentCompleted;

            string value = string.Empty;

            System.Windows.Forms.HtmlElement loginCallOut = ieBrowser.Document.GetElementById("login-callout");
            if (loginCallOut != null && loginCallOut.InnerText.Contains("Trying to sign in?"))
            {
                System.Windows.Forms.HtmlElement cntrlEnail    = ieBrowser.Document.GetElementById("login-email");
                System.Windows.Forms.HtmlElement cntrlPassword = ieBrowser.Document.GetElementById("login-password");
                System.Windows.Forms.HtmlElement cntrlSubmit   = ieBrowser.Document.GetElementById("login-submit");


                if (cntrlEnail != null && cntrlPassword != null && cntrlSubmit != null)
                {
                    cntrlEnail.SetAttribute("value", "*****@*****.**");
                    cntrlPassword.SetAttribute("value", "kareti1024");
                    cntrlSubmit.InvokeMember("click");

                    ieBrowser.DocumentCompleted += IeBrowser_DocumentCompleted1;
                }
            }
        }
Example #8
0
 private static void SetItemLoading(HtmlElement el)
 {
     if (el != null)
         el.SetAttribute("className", "report loading");
 }
Example #9
0
		private void setCheckValue (HtmlElement el, bool check)
		{
			if (check)
				el.SetAttribute("checked", "checked");
			else
				el.SetAttribute("checked", "");
		}
Example #10
0
 public override void SetValue(HtmlElement element)
 {
     element.SetAttribute("value", Value);
 }
Example #11
0
 //Insert values
 public void vl1f()
 {
     hElement1 = webBrowser1.Document.GetElementById(textBoxJSLogin.Text);
     hElement1.SetAttribute("value", textBoxBrowserLogin.Text);
     hElement2 = webBrowser1.Document.GetElementById(textBoxJSPass.Text);
     hElement2.SetAttribute("value", textBoxBrowserPassword.Text);
     hElement3 = webBrowser1.Document.GetElementById(textBoxJSForm.Text);
     hElement3.InvokeMember(textBoxJSSubmit.Text);
 }
Example #12
0
 public void set(HtmlElement elm, string value)
 {
     if (elm == null)
         return;
     elm.SetAttribute("value", value);
     SimpleDocument.fireChange(elm);
 }
Example #13
0
        private void BtnTest1(HtmlElement link)
        {
            string orig_class = (string)link.GetAttribute("className");

            link.SetAttribute("className", orig_class + " " + "directjob_test");
            //link.Focus();
            //MessageBox.Show(link.GetAttribute("classname").ToString());
            IHTMLElement myele = (IHTMLElement)link.DomElement;
            IHTMLDOMNode n1 = (IHTMLDOMNode)myele;

            //MessageBox.Show(n1.nodeName);
            IHTMLAttributeCollection attrcol = (IHTMLAttributeCollection)n1.attributes;

            treeView1.Nodes.Add(myele.tagName);
            treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Add("Attributes");
            if (attrcol != null)
                foreach (IHTMLDOMAttribute iatt1 in attrcol)
                {
                    if (iatt1.nodeValue != null && (iatt1.nodeValue.ToString() != "") && myele.outerHTML.Contains(iatt1.nodeName))
                    //MessageBox.Show("att1 name : "+iatt1.nodeName +"\natt1 value : "+ iatt1.nodeValue.ToString());
                    {
                        //MessageBox.Show("att1 name : " + iatt1.nodeName + "\natt1 value : " + iatt1.nodeValue.ToString());
                        treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes[0].Nodes.Add(iatt1.nodeName, iatt1.nodeName + "=" + iatt1.nodeValue.ToString());
                        treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes[0].LastNode.ToolTipText = iatt1.nodeValue.ToString();
                    }
                }
            if (myele.style.cssText != null && myele.style.cssText.Length > 0)
            {
                treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Add("style", "sytle=" + myele.style.cssText);
                treeView1.Nodes[treeView1.Nodes.Count - 1].LastNode.ToolTipText = myele.style.cssText;
            }
            if (myele.outerText != null && myele.outerText.Length > 0)
            {
                treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Add("outerText", "outerText=" + myele.outerText);
                treeView1.Nodes[treeView1.Nodes.Count - 1].LastNode.ToolTipText = myele.outerText;
            }
            if (myele.outerHTML != null && myele.outerHTML.ToString().Length > 0)
            {
                treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Add("outerHTML", "outerHTML=" + myele.outerHTML.ToString());
                treeView1.Nodes[treeView1.Nodes.Count - 1].LastNode.ToolTipText = myele.outerHTML.ToString();
            }
        }
Example #14
0
		private void SelectResult(int id)
		{
			if(m_hilightedElement != null)
				m_hilightedElement.SetAttribute("className", "result");

			m_hilightedElement = outputBrowser.Document.GetElementById(id.ToString());

			if (m_hilightedElement != null)
			{
				m_hilightedElement.SetAttribute("className", "result hilight");
				int bufferHeight = m_hilightedElement.OffsetRectangle.Height * 3;
				Rectangle viewRect = new Rectangle(
					outputBrowser.Document.Body.ScrollLeft, 
					outputBrowser.Document.Body.ScrollTop + bufferHeight, 
					outputBrowser.Document.Body.ClientRectangle.Width,
					outputBrowser.Document.Body.ClientRectangle.Height - bufferHeight * 2);
				if (!viewRect.IntersectsWith(m_hilightedElement.OffsetRectangle))
				{
					if (m_hilightedElement.OffsetRectangle.Top < viewRect.Top)
						outputBrowser.Document.Body.ScrollTop = Math.Max(0, m_hilightedElement.OffsetRectangle.Top - bufferHeight);
					else
						outputBrowser.Document.Body.ScrollTop = Math.Min(outputBrowser.Document.Body.ScrollRectangle.Height, m_hilightedElement.OffsetRectangle.Bottom - outputBrowser.Document.Body.ClientRectangle.Height + bufferHeight);
				}
			}
		}
Example #15
0
 private static HtmlElement _SetItemSelected(HtmlElement el)
 {
     if (el != null)
         el.SetAttribute("className", "report selected");
     return el;
 }
Example #16
0
 private void BtnTest0(HtmlElement link)
 {
     string orig_class = (string)link.GetAttribute("className");
     if (orig_class.Contains("directjob_test"))
     {
         string ss = orig_class.Replace(" directjob_test", "");
         link.SetAttribute("className", ss);
         //MessageBox.Show(link.GetAttribute("className"));
     }
 }
Example #17
0
        private void CheckElement(HtmlElement ele)
        {
            if (ele != null && ele != hoveringElement)
            {
                if (hoveringElement != null)
                {
                    try
                    {
                        hoveringElement.Style = hoveringElement.GetAttribute("OldStyle");
                    }
                    catch { }
                }

                ele.SetAttribute("OldStyle", ele.Style);
                ele.Style = ele.Style + ";border:solid 1px red;";

                hoveringElement = ele;
            }
        }
Example #18
0
 public void SetValue(HtmlElement elem, string text)
 {
     elem.SetAttribute("value", text);
 }
Example #19
0
 public void SetComboBoxValue(HtmlElement elem, string val)
 {
     elem.SetAttribute("selectedIndex", val);
 }
Example #20
0
 public void SetCheckRadioBox(HtmlElement elem, bool val)
 {
     elem.SetAttribute("checked", val ? "true" : "false");
 }
Example #21
0
        private void CheckElement(HtmlElement ele)
        {
            if (ele != null && ele != hoveringElement)
            {
                if (hoveringElement != null)
                {
                    try
                    {
                        hoveringElement.Style = hoveringElement.GetAttribute("OldStyle");
                    }
                    catch { }
                }

                ele.SetAttribute("OldStyle", ele.Style);
                ele.Style = ele.Style + ";background: #3c3c3c; zoom: 1;filter: alpha(opacity=30);opacity: 0.3;";

                hoveringElement = ele;
            }
        }
 public static void SetHtmlElementValue(HtmlElement he, string value)
 {
     LoggingService.DebugFormatted("将设置{0}-{1}的值:{2}", new object[] { he.Document.Url.ToString(), he.Id, value });
     he.SetAttribute("value", value);
     if (he.TagName.ToLower() == "select")
     {
         string attribute = he.GetAttribute("valuechange");
         if ((attribute != null) && (attribute.Length > 0))
         {
             he.Document.InvokeScript(attribute, new string[] { value });
         }
     }
 }
Example #23
0
        protected void UpdateUrlAbsolute(HtmlElement ele)
        {
            HtmlElementCollection eleColec = ele.GetElementsByTagName("IMG");
            foreach (HtmlElement it in eleColec)
            {
                it.SetAttribute("src", it.GetAttribute("src"));
            }
            eleColec = ele.GetElementsByTagName("A");
            foreach (HtmlElement it in eleColec)
            {
                it.SetAttribute("href", it.GetAttribute("href"));
            }

            if (ele.TagName == "A")
            {
                ele.SetAttribute("href", ele.GetAttribute("href"));
            }
            else if (ele.TagName == "IMG")
            {
                ele.SetAttribute("src", ele.GetAttribute("src"));
            }
        }
Example #24
0
 private static void SetItemUnselected(HtmlElement el)
 {
     if (el != null)
         el.SetAttribute("className", "report");
 }
Example #25
0
 void startMoving()
 {
     DataTable dt = ds.Tables["Log"];
     // 获取控件
     getHtmlDoc().GetElementById("articleTitle").InnerText = dt.Rows[0]["Title"].ToString();
     getHtmlDoc().GetElementById("SinaEditor_59_viewcodecheckbox").InvokeMember("click");
     getHtmlDoc().All["SinaEditorTextarea"].InnerText = dt.Rows[0]["Content"].ToString() + "<br />" + dt.Rows[0]["LogDate"].ToString();
     getHtmlDoc().GetElementById("SinaEditor_59_viewcodecheckbox").InvokeMember("click");
     heCategory = getHtmlDoc().GetElementById("componentSelect");
     foreach (HtmlElement heCategoryOption in heCategory.GetElementsByTagName("option"))
     {
         if (heCategoryOption.InnerText == dt.Rows[0]["Sort"].ToString())
             heCategoryValue = heCategoryOption.GetAttribute("value");
     }
     heCategory.SetAttribute("value", heCategoryValue);
     if (dt.Rows[0]["Tags"].ToString().Trim() != "")
         getHtmlDoc().GetElementById("articleTagInput").InnerText = dt.Rows[0]["Tags"].ToString(); ;
     //getHtmlDoc().GetElementById("input1").InvokeMember("click");
     //getHtmlDoc().GetElementById("input2").InvokeMember("click");
     getHtmlDoc().GetElementById("articlePostBtn").InvokeMember("click");
     isCompleteForAddLog = true;
 }
Example #26
0
 private void InputValue(HtmlElement element, string value)
 {
     element.SetAttribute("value", value);
     webBrowser.Select();
     webBrowser.Focus();
     element.Focus();
     System.Windows.Forms.SendKeys.Send("{tab}");
     System.Windows.Forms.SendKeys.Send(" ");
 }