得到IE的内容比较准确的一个方法

声明:下列代码转自: http://stackoverflow.com/questions/3759569/watin-core-ie-component-giving-timeout-while-internet-explorer-busy-error-while

可以帮忙解决用Watin进行Web测试时IE对象可能出现的问题:
public
classStaticIE:IDisposable
{
   
private IE _ie;
   
privateint _ieThread;
   
privatestring _ieHwnd;
   
privateint _processId;

   
publicStaticIE(IE aBrowser)
   
{
       
SetBrowser(aBrowser);
   
}

   
public IE Browser
   
{
        get
       
{
           
var currentThreadId =GetCurrentThreadId();
            _ie
=Browser.AttachTo<IE>(Find.By("hwnd", _ieHwnd),1);
           
if(currentThreadId != _ieThread)
           
{
                _ieThread
= currentThreadId;
           
}
           
return _ie;
       
}
   
}

   
privatevoidSetBrowser(IE aBrowser)
   
{
        _ie
= aBrowser;
        _ieHwnd
= _ie.hWnd.ToString();
        _ieThread
=GetCurrentThreadId();
        _processId
= _ie.ProcessID;
   
}

   
privateintGetCurrentThreadId()
   
{
       
returnThread.CurrentThread.GetHashCode();
   
}

   
publicvoidDispose()
   
{
       
if(_ie !=null)
       
{
           
Process.GetProcessById(_processId).Kill();
            _ie
=null;
       
}
   
}
}
posted @ 2012-07-06 17:50  betrueMM  阅读(163)  评论(0编辑  收藏  举报