Click the HTML link inside the WebBrowser control

C # Visual Studio 2010

I am loading a complex html page into a webbrowser control. But I do not have the ability to change the web page. I want to click a link on a page automatically from a window form. But the identifier is created randomly every time the page is loaded (so I believe that the link to the ID will not work).

This is the contents of the href link:

<a 

id="u_lp_id_58547" href="javascript:void(0)" class="SGLeftPanelText" onclick="setStoreParams('cases;212', 212); window.leftpanel.onClick('cases_ss_733');return false; ">

 My Assigned</a> 

Anyway, click the link from C #?

Thanks!


UPDATE:

It seems to me that this is close, but it just does not work:

 HtmlElementCollection links = helpdeskWebBrowser.Document.Window.Frames["main_pending_events_frame"].Document.GetElementsByTagName("a"); MessageBox.Show(links.Count.ToString()); 

I tried connecting every frame name and tried both "a" and "A" in the TagName field, but just no luck. I can not find any links; the message field is always 0. What am I missing?

+6
c # browser visual-studio-2010 hyperlink
source share
2 answers

Something like this should work:

 HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547") link.InvokeMember("Click") 

EDIT:

Since identifiers are randomly generated, another option would be to identify the links by their InnerText ; along these lines.

 HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A"); foreach (HtmlElement link in links) { if (link.InnerText.Equals("My Assigned")) link.InvokeMember("Click"); } 

UPDATE:

You can get links in an IFrame using:

 webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A"); 
+17
source share

You may need to isolate the link identifier value using more of the surrounding HTML context as the β€œtarget” and then retrieve a new random identifier.

In the past, I used " HtmlAgilityPack " to easily parse "screen- scanned " HTML to isolate areas of interest within a page - this library seems easy to use and reliable.

+1
source share

All Articles