日期:2014-05-19  浏览次数:20852 次

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

------解决方案--------------------
不如用WatiN测试
------解决方案--------------------
鼠标右键事件里写吧,可能要简单些
------解决方案--------------------
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;
}
为了你这问题还专门写了上述代码测试,希望对你有所启发