SHDocVw.InternetExplorer找到浏览器后查找内容中某项并点击

zwl12549 2014-07-22 03:09:58
oreach (SHDocVw.InternetExplorer ie in shellWindows)   
{
//if it is ie window
if (ie.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)
{
//get the document displayed
ieDoc = (mshtml.IHTMLDocument2)ie.Document;
if (ieDoc.title.ToUpper().IndexOf("GOOGLE") >= 0)
{
ieWnd = ie;
break;
}
}
}

...
IHTMLElement htmlElement =doc.getElementById("Header")//这里可以找到

IHTMLElementCollection childs = parentElement.all;//查找子项时各种尝试都没成功,找不到子项返回都是“System.__ComObject”的 COM 对象不能转换为IHTMLElement
IHTMLElement h3 = childs.item("h3");
HTMLDivElement div = (HTMLDivElement)parentElement;
IHTMLDOMNode node = div.firstChild;
IHTMLDOMNode lnk = node.firstChild;
MessageBox.Show(node.nodeValue);

类似这样得到的SHDocVw.InternetExplorer,然后查找某ID项,再查找该项中某子项并点击.
某ID项可以查找到,子项查找不出来,也无法转换为IHTMLElement也就无法控制点击。
...全文
184 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangnaisheng 2014-07-22
  • 打赏
  • 举报
回复
引用 3 楼 zwl12549 的回复:
[quote=引用 2 楼 wangnaisheng 的回复:] http://blog.csdn.net/hanjieson/article/details/8574093
坑爹啊~百度,搜索不到什么东西,google老屏蔽,用bing英文才搜索到, 我代码有个错误
IHTMLElementCollection childs = parentElement.all//这里没有强制转换
改成
IHTMLElementCollection childs = (IHTMLElementCollection)parentElement.all
这样就ok了,我擦。。。。郁闷。。就你回复分给你了 [/quote] 给你一个google的链接,可用的哈。 https://wen.lu/
zwl12549 2014-07-22
  • 打赏
  • 举报
回复
引用 2 楼 wangnaisheng 的回复:
http://blog.csdn.net/hanjieson/article/details/8574093
坑爹啊~百度,搜索不到什么东西,google老屏蔽,用bing英文才搜索到, 我代码有个错误
IHTMLElementCollection childs = parentElement.all//这里没有强制转换
改成
IHTMLElementCollection childs = (IHTMLElementCollection)parentElement.all
这样就ok了,我擦。。。。郁闷。。就你回复分给你了
zwl12549 2014-07-22
  • 打赏
  • 举报
回复
之前发个帖子也没解决,几乎同一个问题,有朋友帮忙解决去留言再送100分 http://bbs.csdn.net/topics/390839955?page=1#post-397819270

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧