因为自动化测试的需要,要做一个小工具,读出当前鼠标位置的网页文档元素的ID以及所在的<TD></TD>内的其他内容,用C#来写,不知道该怎么做了?还望各位高手指点一二。

解决方案 »

  1.   

    如果用鼠标键来触发,应该怎么做呢?
    要求是:点下鼠标中键,将鼠标当前所在位置的网页元素ID啊,Title啊,Class,OuterHtml等等输出到一个window窗体的几个文本框里。
    IE的DevToolbar工具用起来也不方便,网页对话框里的网页元素ID就不好捕捉。
      

  2.   

    InternetExplorerClass m_IE = null;
    m_IE=new InternetExplorerClass();
    m_IE.Silent=true;
    stbr.Text="正在打开IE...";
    object o=null;
    m_IE.Navigate("http://mail.163.com/",ref o,ref o,ref o,ref o);
    //等待网页加载完毕
    HTMLDocument doc=(HTMLDocument)m_IE.Document;
    HTMLDocumentEvents2_Event mouseMoveEvent=(HTMLDocumentEvents2_Event)doc;
    mouseMoveEvent.onmousemove+=new HTMLDocumentEvents2_onmousemoveEventHandler(mouseMoveEvent_onmousemove);
    -----------------------------------------------------------------
    private void mouseMoveEvent_onmousemove(IHTMLEventObj pEvtObj)
    {
    IHTMLElement mouse_ime=pEvtObj.srcElement;
    this.Text=(mouse_ime==null||mouse_ime.innerHTML==string.Empty)?"null":mouse_ime.innerText;
    }
    为了你这问题还专门写了上述代码测试,希望对你有所启发
      

  3.   

    少写了一句:
    m_IE.Visible=true;
    不然你没法见到IE浏览器
      

  4.   

    HTMLDocument doc=(HTMLDocument)m_IE.Document;
    这句话调试时没过,555。
    错误:"对 COM 组件的调用返回了错误 HRESULT E_FAIL。"
      

  5.   

    你要在项目引用中添加mshtml的引用