日期:2014-05-18 浏览次数:21030 次
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Drawing;
using Shrinerain.AutoTester.HTMLUtility;
namespace Shrinerain.AutoTester
{
class Baidu
{
public static void Main()
{
string url = @"http://www.baidu.com/";
string title="百度一下";
HTMLTest test = new HTMLTest();
//test.Browser.Find(title);
//test.SendMsgOnly = true;
test.Browser.Load(url);
test.Map.TextBox().Input("测试");
test.Map.Button("百度一下").Click();
Console.ReadLine();
}
}
}
------解决方案--------------------
有以下几个步骤:
1、平台调用包装两个API函数:InternetGetCookies和InternetSetCookies
这是最基本的cookies处理函数.
2、建立一个CookieContainer,把本地包括的cookies使用InternetGetCookies添加到这个CookieContainer中。
3、先是使用HttpWebRequst发送请求,当然要指定CookieContainer,后接收到HttpWebResponse后,要把
CookieContainer中的相应cookies使用InternetSetCookies写入到本地cookies缓存中。
4、使用WebBrowser控件请求页面,这是的WebBrowser控件默认能从本地cookies缓存中搜索到cookies并发送出去
了。
以上步骤中间还有些小的问题需要你自己解决,比如向CookieContainer中添加和读取cookie等。
以上说的是使用WebBrowser控件时注意的问题。
其实,你的那个方法也是可行的。
问题出在你的mshtml的版本身上。只要两台计算机的mshtml版本一样,应该都能运行,楼主检查一下版本吧!
------解决方案--------------------