如何调用单击Web浏览器中的链接? [英] How to invoke click on a link in the web browser?

查看:138
本文介绍了如何调用单击Web浏览器中的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我们可以说该页面包含一个名为关于我们的链接。而不是我这样做:

Okay lets say the page contains a link called 'About Us'. Instead of me doing:

webBrowser.Navigate ("www.page.com/aboutus");

...如何告诉我的程序点击包含关于我们的文字的任何链接?

...how can I tell my program to click any link that contains the text About Us?

我知道这可能看起来像我做了更多的工作然后我也有,但相信我需要这些代码。

I know this might seem like Im doing more work then necessary I have too but trust me I need this bit of code.

任何帮助将不胜感激,谢谢:)

Any help would be appreciated, thanks :)

推荐答案

您需要找到 HtmlElement < a> 标记的对象,然后调用 InvokeMember(click)

You need to find the HtmlElement object for the <a> tag, then call InvokeMember("click").

如果元素有ID,您可以通过调用 Document.GetElementById 来获取它。否则,您可以查看 GetElementsByTagName 并找到您要查找的元素。

If the element has an ID, you can get it by calling Document.GetElementById; otherwise, you can look through GetElementsByTagName and find the element you're looking for.

这篇关于如何调用单击Web浏览器中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆