日期:2014-05-17  浏览次数:20427 次

C#web自动化测试问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics; 
using System.Threading; 
using SHDocVw; 
using mshtml;

namespace TestProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Launching IE ...");
            Process p = Process.Start("iexplore.exe", "about:blank");
            Thread.Sleep(3000);
            Console.WriteLine("Attaching to IE ...");
            InternetExplorer ie = null;
            if (p != null)
            {
                SHDocVw.ShellWindows allBrowser = new ShellWindows();
                if (allBrowser.Count != 0)
                {
                    for (int i = 0; i < allBrowser.Count; i++)
                    {
                        InternetExplorer e = (InternetExplorer)allBrowser.Item(i);
                        if (e.HWND == (int)p.MainWindowHandle)
                        {
                            ie = e;
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Error: Can not Launch IE");