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"); }
public void MatchWeb() { IEOperateCore ieCore = new IEOperateCore("http://psgpms.chinasofti.com/main.jsp"); HTMLFrameElementClass iframe = ieCore.GetInputElementByID <HTMLFrameElementClass>("ManagerTopFrame"); IHTMLDocument2 doc = iframe.contentWindow.document; HTMLBodyClass bodyClass = (HTMLBodyClass)doc.body; IHTMLElementCollection aLinkElementCollection = bodyClass.getElementsByTagName("a"); foreach (HTMLAnchorElementClass item in aLinkElementCollection) { if (item.title.Equals("退出系统")) { item.click(); break; } } IntPtr ieDialogWindowHWND = ieCore.FindWindow(null, "来自网页的消息"); Thread.Sleep(2000); IntPtr childHwnd = Win32.FindWindowEx(ieDialogWindowHWND, IntPtr.Zero, null, "取消"); //获得查询按钮的句柄 if (childHwnd != IntPtr.Zero) { Win32.SendMessage(childHwnd, Win32.BM_CLICK, IntPtr.Zero, IntPtr.Zero);//发送点击按钮的消息 } }
public void CaptureTableData() { StringBuilder buffer = new StringBuilder(); IEOperateCore ieCore = new IEOperateCore("http://psgpms.chinasofti.com/main.jsp"); HTMLFrameElementClass iframe = ieCore.GetInputElementByID <HTMLFrameElementClass>("mainFrame"); IHTMLDocument2 doc = iframe.contentWindow.document; HTMLBodyClass bodyClass = (HTMLBodyClass)doc.body; IHTMLElementCollection tableElementCollection = bodyClass.getElementsByTagName("table"); foreach (HTMLTableClass table in tableElementCollection) { if (null != table.id && table.id.Equals("rossTableId_TASK")) { foreach (HTMLTableRowClass row in table.rows) { foreach (HTMLTableCellClass cell in row.cells) { if (null != cell.innerText) { buffer.Append(cell.innerText + " "); } } buffer.Append("/r/n"); } break; } } }
/// <summary> /// 此方法是查找iframe下的a标签,查找规则是根据提供的searchKey查找指定的属性内容,默认直返回第一个被查找到的元素 /// </summary> /// <param name="iframe"></param> /// <param name="searchKey"></param> /// <param name="isFindByTitle"></param> /// <param name="isFindByClassName"></param> /// <returns></returns> public HTMLAnchorElementClass Get_Alink_From_IFrame(HTMLFrameElementClass iframe, string searchKey, bool isFindByTitle = true, bool isFindByClassName = false) { HTMLAnchorElementClass aLink = null; IHTMLElementCollection aLinkElementCollection; IHTMLDocument2 doc; HTMLBodyClass bodyClass; doc = iframe.contentWindow.document; bodyClass = (HTMLBodyClass)doc.body; aLinkElementCollection = bodyClass.getElementsByTagName("a"); foreach (HTMLAnchorElementClass item in aLinkElementCollection) { if (isFindByTitle) { if (null != item.title && item.title.Equals(searchKey)) { aLink = item; break; } } else if (isFindByClassName) { if (null != item.className && item.className.Equals(searchKey)) { aLink = item; break; } } } return(aLink); }