public void AppendAllChildElement(CefDomNode parentNode,CwbElement parentElement, string indePath) { if (parentNode.HasChildren) { CefDomNode node = parentNode.FirstChild; if (node == null) return; int index = 0; CwbElement childElement = CreateElement(node); childElement.IndexPath = indePath + "."+index.ToString(); parentElement.ChildElements.Add(childElement); AppendAllChildElement(node, childElement, childElement.IndexPath); node = node.NextSibling; while (node != null) { childElement = CreateElement(node); index++; childElement.IndexPath = indePath + "." + index.ToString(); parentElement.ChildElements.Add(childElement); AppendAllChildElement(node, childElement, childElement.IndexPath); node = node.NextSibling; System.Windows.Forms.Application.DoEvents(); } } }
private void documentToolStripMenuItem_Click(object sender, EventArgs e) { CwbElement root = chromeWebBrowser1.Document.Root; string value = root.ChildElements[0].ChildElements[1].ChildElements[3].Value; MessageBox.Show(value); }
private void getAttributeToolStripMenuItem_Click(object sender, EventArgs e) { string value = string.Empty; CwbElement buttons = chromeWebBrowser1.Document.GetElementById("kw1"); value = buttons.GetAttribute("value"); MessageBox.Show(value); }
private void visitAttrToolStripMenuItem_Click(object sender, EventArgs e) { string value = string.Empty; CwbElement buttons = chromeWebBrowser1.Document.GetElementById("kw1"); foreach (KeyValuePair <string, string> item in buttons.Attributes) { value += item.Key + ":" + item.Value + ","; } MessageBox.Show(value); }
private CwbElement CreateElement(CefDomNode node) { string id = string.Empty; if (node.HasAttribute("id")) { id = node.GetAttribute("id"); } CwbElement retValue = new CwbElement(browser,id, node.ElementTagName,node.GetAttribute("value"), node.IsElement,node.IsEditable, node.HasChildren,node.InnerText, node.HasAttributes ); foreach (KeyValuePair<string, string> item in node.GetAttributes()) { retValue.Attributes.Add(item); } return retValue; }
protected override void Visit(CefDomDocument document) { CefDomNode element; switch (_businID) { case CwbBusinStyle.bsGetElementValue: Global.Result = ""; element = document.GetElementById(_elementID); if (element == null) { Global.flag = true; return; } Global.Result = element.Value; if (element.ElementTagName.ToLower() != "input") Global.Result = element.InnerText; Global.flag = true; break; case CwbBusinStyle.bsSetElementValue: element = document.GetElementById(_elementID); if (element == null) return; if (element.IsEditable) element.SetAttribute("value", _elementValue); else { string code = "document.getElementById('{0}').innerHTML = '{1}';"; code = string.Format(code,_elementID,_elementValue); Global.instance.ExecuteScript(code); } break; case CwbBusinStyle.bsAddElementEvent: element = document.GetElementById(_item.id); if (element == null) return; element.AddEventListener(_item.eventName,new RSEventListener(_item.elementListener),true); break; case CwbBusinStyle.bsVisitDocument: Global.flag = false; CefDomNode root = document.Root; CwbElement Root = CreateElement(root); if (Global.RootList.ContainsKey(browser.Identifier)) { Global.RootList[ browser.Identifier ] = Root; } else { Global.RootList.Add(browser.Identifier, Root); } string indexPath = "0"; Root.IndexPath = indexPath; AppendAllChildElement(root, Root, indexPath); Global.flag = true; break; case CwbBusinStyle.bsAttachElementEvent: CefDomNode root1 = document.Root; string indexPath1 = "0"; AttachEventHandler(root1, indexPath1, new RSEventListener(_item.elementListener)); Global.flag = true; break; } _businID = CwbBusinStyle.bsNone; }
private void appElementListenerToolStripMenuItem_Click(object sender, EventArgs e) { CwbElement buttons = chromeWebBrowser1.Document.GetElementById("su"); buttons.AttachEventListener("click", new ChromeWebBrowser.TCallBackElementEventListener(showmsg)); }
private void clickToolStripMenuItem_Click(object sender, EventArgs e) { CwbElement buttons = chromeWebBrowser1.Document.GetElementById("su"); buttons.Click(); }
private void setAttributeToolStripMenuItem_Click(object sender, EventArgs e) { CwbElement buttons = chromeWebBrowser1.Document.GetElementById("kw1"); buttons.SetAttribute("value", "test value"); }
private void getElementByIdToolStripMenuItem_Click(object sender, EventArgs e) { CwbElement buttons = chromeWebBrowser1.Document.GetElementById("kw1"); MessageBox.Show(buttons.Value); }
private void setElementValueToolStripMenuItem1_Click(object sender, EventArgs e) { CwbElement root = chromeWebBrowser1.Document.Root; root.ChildElements[0].ChildElements[1].ChildElements[3].Value = "test value"; }
private void doSomthing() { while (true) { int money = 0; if (this.isStop) { return; } try { this.MoneyTextElement = this.chromeWebCrowser.Document.GetElementById(this.MoneyTextID); this.MoneyPlusElement = this.chromeWebCrowser.Document.GetElementById(this.MoneyPlusButtonID); this.MoneySubmitElement = this.chromeWebCrowser.Document.GetElementById(this.MoneySubmitButtonID); if (int.TryParse(this.MoneyTextElement.Value, out money)) { if (money < this.many) { this.MoneyPlusElement.Click(); if (System.Configuration.ConfigurationSettings.AppSettings["needsleep"] == "true") { System.Threading.Thread.Sleep(200); } } MethodInvoker invoker = delegate { this.labMany.Text = this.MoneyTextElement.Value; }; if ((!base.IsDisposed) && base.InvokeRequired) { base.Invoke(invoker); } else { invoker(); } int.TryParse(this.MoneyTextElement.Value, out money); if (money == this.many) { // this.MoneySubmitElement.Click(); MethodInvoker invoker1 = delegate { this.labMany.Visible = false; this.labelX9.Visible = false; this.labelX7.Text = "当前值已达到目标值" + money.ToString() + "万元,已提交"; MessageBox.Show("当前值已达到目标值" + money.ToString() + "万元,已提交"); }; if ((!base.IsDisposed) && base.InvokeRequired) { base.Invoke(invoker1); } else { invoker1(); } break; } if (money > this.many) { MethodInvoker invoker1 = delegate { this.labMany.Visible = false; this.labelX9.Visible = false; this.labelX7.Text = "当前值超过目标值,退出监控"; this.isStop = true; this.btnStart.Enabled = true; this.progressBarX1.Text = "监控已停止..."; this.progressBarX1.ProgressType = DevComponents.DotNetBar.eProgressItemType.Standard; MessageBox.Show("当前值超过目标值,退出监控"); }; if ((!base.IsDisposed) && base.InvokeRequired) { base.Invoke(invoker1); } else { invoker1(); } break; } } } catch { } System.Threading.Thread.Sleep(100); } MethodInvoker invoker2 = delegate { this.isStop = true; this.btnStart.Enabled = true; this.progressBarX1.Text = "监控已停止..."; this.progressBarX1.ProgressType = DevComponents.DotNetBar.eProgressItemType.Standard; this.labelX9.Visible = false; this.labMany.Visible = false; }; if ((!base.IsDisposed) && base.InvokeRequired) { base.Invoke(invoker2); } else { invoker2(); } }