1
//引用COM组件
//Microsoft HTML Object Library
//Microsoft Internet Controls
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); 2 string filename; 3 foreach (SHDocVw.InternetExplorer ie in shellWindows) 4 { 5 filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); 6 if (filename.Equals("iexplore")) 7 { 8 SetText(string.Format("Web Site : {0}", ie.LocationURL)); 9 mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2; 10 SetText(string.Format(" Document Snippet: {0}", 11 ((htmlDoc != null) ? htmlDoc.body.outerHTML 12 : "***Failed***"))); 13 SetText(string.Format("{0}{0}", Environment.NewLine)); 14 15 mshtml.HTMLInputElementClass input; 16 mshtml.HTMLIFrameClass iframe; 17 mshtml.IHTMLDocument2 target; 18 //获取父页面框架集合. 19 mshtml.IHTMLFramesCollection2 frames = htmlDoc.frames; 20 for (int i = 0; i < frames.length; i++) 21 { 22 object index = i; 23 mshtml.IHTMLWindow2 frame = frames.item(ref index) as mshtml.IHTMLWindow2; 24 25 mshtml.IHTMLDocument2 frameDoc = frame.document as mshtml.IHTMLDocument2; 26 //现在你可以通过frameDoc获取子页面控件. 27 28 if (frame.location.href.Contains("zzs_fp.html")) 29 { 30 target = frameDoc; 31 32 33 foreach (mshtml.IHTMLElement ieElement in target.all) 34 { 35 if (ieElement.tagName.ToUpper().Equals("INPUT")) 36 { 37 input = ((mshtml.HTMLInputElementClass)ieElement); 38 39 SetText("input.name:" + input.name); 40 SetText(string.Format("{0}{0}", Environment.NewLine)); 41 42 if (input.name == "ghdwmc") 43 { 44 input.value = "****"; 45 } 46 else if (input.name == "ghdwsh") 47 { 48 input.value = "12300000747150428A"; 49 } 50 else if (input.name == "ghdwdzdh") 51 { 52 input.value = "北京市 010-512011"; 53 } 54 else if (input.name == "ghdwyhzh") 55 { 56 input.value = "北京银行 132465798798"; 57 } 58 } 59 } 60 } 61 } 62 } 63 }