How to invoke click on a link in the web browser?

2019-08-18 23:13发布

问题:

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 :)

回答1:

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

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.