private void TestElementXPath(string DataQAValue, string FireBugXPath) { //Confirm FireBug provided a valid Xpath and item is found // Find the element by QA data tag value mshtml.IHTMLElement e = GetElementbyDataQA(DataQAValue); if (e == null) { throw new Exception("Element not found - " + DataQAValue); } // Calc the Xpath - this is what we want to test for accuracy and make sure it find the correct element string XPath = MBW.GetElementXPath(e); mshtml.IHTMLElement n2 = MBW.GetElementByXPath(XPath); if (n2 == null) { throw new Exception("Element not found by XPath - " + XPath); } string QA2 = n2.getAttribute("data-QA"); if (QA2 != DataQAValue) { throw new Exception("ERROR: QA2 != DataQAValue - " + QA2); } //Validate we found the same exact element based on QA tag - Unique Assert.AreEqual(QA2, DataQAValue); // Check if we created same XPath - can be different so fail only if QA2 != DataQAValue , else warning //TODO: Make warning - not fail!! can be several XPath to same element //Assert.AreEqual(FireBugXPath, XPath); // False alarm so removed }
//网页加载完成,回调函数 private void onLoadDocCompleted(object sender, NavigationEventArgs e) { if (!isFresh) //如果刷新状态不执行任何动作 { //获取文档对象 mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)web1.Document; //判断:登录状态。登录状态通过网页标题判断。 if (doc2.title == "红警之坦克风暴 - 应用中心") { //获取游戏框架的iframe节点 mshtml.IHTMLElement m_iframe = (mshtml.IHTMLElement)doc2.all.item("app_frame", 0); //获取该节点的src属性。即为游戏的免登陆URL game_url = (string)m_iframe.getAttribute("src"); //把提取到的免登陆URL写入配置文件 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa.AppSettings.Settings["Game"].Value = game_url; //写入游戏URL cfa.AppSettings.Settings["Status"].Value = "secondtime"; //写入第二次登录标记 cfa.Save(); //重新载入免登陆URL。目的:去除腾讯QQ空间的外部框架,去除广告。 Uri uri = new Uri(game_url); web1.Navigate(uri); //启动定时器,用于刷新计时 timer.Start(); //把刷新状态改为真,进入刷新状态。网页加载完成不再执行提取操作。 isFresh = true; } } }
public string GetAttribute(string attributeName) { //return underlying.GetAttribute(attributeName); mshtml.IHTMLElement element = (mshtml.IHTMLElement)underlying.DomElement; object result = element.getAttribute(attributeName); return(result != null?result.ToString() : null); }
//委托函数--转到框架 private void SelectLoginiFrame() { mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web1.Document; mshtml.IHTMLElement l_iframe = (mshtml.IHTMLElement)doc.all.item("login_frame", 0); string zoneurl = (string)l_iframe.getAttribute("src"); Uri li_uri = new Uri(zoneurl); web1.Navigate(li_uri); }
private string GetElementTextById(string id) { try { mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)webBrowser1.Document; mshtml.IHTMLElement element = doc2.all.item(id, 0); return(element.getAttribute("InnerText")); } catch (Exception) { return(null); } }
public static bool IsPlaceholder(mshtml.IHTMLElement element, bool atomic = false) { if (element == null) { return(false); } if (!element.tagName.Equals(PlaceHolderTag, StringComparison.InvariantCultureIgnoreCase)) { return(false); } if (!atomic) { return(true); } var result = element.getAttribute(AtomicAttribute); return((result != null) && result.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)); }
private void IEModule_OnShowContextMenu(object sender, ADXIEShowContextMenuEventArgs e) { // Only controls if (e.ContextMenu != ADXIEShowContextMenuEventArgs.ADXIEDocContextMenu.Control) { return; } TargetElem = e.HTMLElement as mshtml.IHTMLElement; // Only input controls but no buttons if (TargetElem.tagName.ToLower().Equals("input") && !TargetElem.getAttribute("type").ToString().ToLower().Equals("submit")) { e.Handled = true; // Disabling menus if no password is selected in the list toolStripAddLogin.Enabled = Tools.IdCurrentPassword != null; toolStripAddPassword.Enabled = Tools.IdCurrentPassword != null; contextMenu.Show(e.Location); } }
public CompanyCmsData GenerateCCD(string html) { CompanyCmsData item = new CompanyCmsData(); mshtml.HTMLDocumentClass doc = new mshtml.HTMLDocumentClass(); doc.designMode = "on"; doc.IHTMLDocument2_write(html); mshtml.IHTMLElement noteEle = doc.getElementById("note"); //公司简介 if (noteEle != null) { item.CompanyDesp = string.IsNullOrEmpty(noteEle.innerText) ? "" : noteEle.innerText.Trim(); } else { return(null); } mshtml.IHTMLElement ele = doc.getElementById("registeredAddress"); //注册地址 if (ele.getAttribute("value") != null) { item.RegisterAddress = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("address"); //地址 if (ele.getAttribute("value") != null) { item.RealAddress = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("businessLicense"); //营业执照号 if (ele.getAttribute("value") != null) { item.CompanyIdNo = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("email"); //营业执照号 if (ele.getAttribute("value") != null) { item.CompanyEmail = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("legalRepresentative"); //法人 if (ele.getAttribute("value") != null) { item.LegalPerson = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("contact"); //联系人 if (ele.getAttribute("value") != null) { item.ContactPerson = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("phone"); //电话 if (ele.getAttribute("value") != null) { item.ContactPhone = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("accountName"); //tts的admin账号 if (ele.getAttribute("value") != null) { item.TTSAdminAccount = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } mshtml.IHTMLElementCollection eles = doc.getElementsByName("promotionNameDomestic"); if (eles != null && eles.length > 0) { ele = (mshtml.IHTMLElement)eles.item(0); if (ele.getAttribute("value") != null) { item.GuoneiWebName = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } } eles = doc.getElementsByName("promotionNameInternational"); if (eles != null && eles.length > 0) { ele = (mshtml.IHTMLElement)eles.item(0); if (ele.getAttribute("value") != null) { item.GuojiWebName = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } } ele = doc.getElementById("bossBackgrouds"); //公司简介 item.BossBackground = string.IsNullOrEmpty(ele.innerText) ? "" : ele.innerText.Trim(); return(item); }
//Step 2 (WHILE) public bool DoStep2_Set(int startIdx = 0) { mshtml.HTMLDocument Doc = default(mshtml.HTMLDocument); mshtml.IHTMLElementCollection eles = default(mshtml.IHTMLElementCollection); Doc = (mshtml.HTMLDocument)Ie.Document; mshtml.HTMLWindow2 fra = Pub_Com.GetFrameWait(ref Ie, "fraHyou"); while (ReferenceEquals(fra, null)) { Com.Sleep5(1000); fra = Pub_Com.GetFrameWait(ref Ie, "fraHyou"); } Pub_Com.SleepAndWaitComplete(Ie); Doc = (mshtml.HTMLDocument)fra.document; eles = Doc.getElementsByTagName("input"); Pub_Com.SleepAndWaitComplete(Ie); Com.Sleep5(1000); if (eles.length == 0) { MessageBox.Show("明細がありません、多分発注した件数多いです"); Ie.Visible = true; System.Environment.Exit(0); return(false); } for (int i = startIdx; i <= eles.length - 1; i++) { mshtml.IHTMLElement ele = (mshtml.IHTMLElement)(eles.item(i)); if (ReferenceEquals(ele, null)) { continue; } try { if (ele.getAttribute("name").ToString() == "strMitKbnHen") { mshtml.IHTMLTableRow tr = (mshtml.IHTMLTableRow)ele.parentElement.parentElement; mshtml.HTMLTableCell td = (mshtml.HTMLTableCell)(tr.cells.item(4)); if (td.innerText == "作成中") { ele.click(); Pub_Com.GetElementBy(ref Ie, "fraHead", "input", "value", "発注納期非表示").click(); Pub_Com.SleepAndWaitComplete(Ie); mshtml.HTMLDocument Doc1 = (mshtml.HTMLDocument)Ie.Document; mshtml.HTMLWindow2 fra1 = Pub_Com.GetFrameWait(ref Ie, "fraMitBody"); Doc1 = (mshtml.HTMLDocument)fra1.document; if (Doc1.body.innerText.IndexOf("発注可能な見積ではありません") > 0) { Ie.GoBack(); Pub_Com.SleepAndWaitComplete(Ie); return(DoStep2_Set(i + 1)); } else { return(true); } } } } catch (Exception) { } } return(false); }