当前位置:编程学习 > C#/ASP.NET >>

【新人求助】有关于如何获取InternetExplorer类的源代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using SHDocVw;
using mshtml;
using System.IO;
namespace AutoTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Step1:启动IE浏览器");
            InternetExplorer ie = new InternetExplorer();
            object obj = null;
            ie.Visible = true;
            string strURL = "http://www.baidu.com/";
            ie.Navigate(strURL, ref obj, ref obj, ref obj, ref obj);
            while (ie.Busy || ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)
            {
                Thread.Sleep(200);
            }
            Console.WriteLine("Step2:输入搜索值");
            HTMLDocument doc = (HTMLDocument)ie.Document;
            HTMLInputElement txtKeyword = (HTMLInputElement)doc.getElementById("wd");
            txtKeyword.value = "文艺青年";
            while (ie.Busy || ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)
            {
                Thread.Sleep(200);
            }

            Console.WriteLine("Step3:提交请求");
            HTMLInputElement bnSubmit = (HTMLInputElement)doc.getElementById("su");
            bnSubmit.click();
            while (ie.Busy || ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)
            {
                Thread.Sleep(200);
            }
            Console.WriteLine("Step4:测试");
            if (string.Equals(doc.title.Trim(), "百度搜索_文艺青年"))
            {
                Console.WriteLine("通过测试:标题正确");
            }
            else
            {
                Console.WriteLine("未能通过测试:标题不正确");
            }
            while (ie.Busy || ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)
            {
                Thread.Sleep(200);
            }
            Console.WriteLine("Step5:自动化测试结束");
            Console.Read();
        }
    }
}

这是我的代码,我想在bnSubmit.click();之后,获取到跳转到的网页的源代码。
求教~~~ --------------------编程问答-------------------- HTMLDocument doc = (HTMLDocument)ie.Document;
string html = doc.InnerHTML; --------------------编程问答-------------------- 上面的正解。 --------------------编程问答--------------------
引用 1 楼 caozhy 的回复:
HTMLDocument doc = (HTMLDocument)ie.Document;
string html = doc.InnerHTML;

为什么我加了这段代码之后产生了错误。
IDE不识别doc.InnerHTML;
是我没有填加什么引用么? --------------------编程问答-------------------- 求助攻 --------------------编程问答--------------------
引用 3 楼 rowanhaoa 的回复:
Quote: 引用 1 楼 caozhy 的回复:

HTMLDocument doc = (HTMLDocument)ie.Document;
string html = doc.InnerHTML;

为什么我加了这段代码之后产生了错误。
IDE不识别doc.InnerHTML;
是我没有填加什么引用么?

doc没有InnerHtml属性,HTMLElement才有 --------------------编程问答-------------------- webBrowser1.Document.Body.InnerHtml
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,