I have a Windows aplication where i want to click a link in a website automatically after an automatic login.Now i am done with automatic log in.but unable to click the link which is enclosed inside <a> tag
eg:
<a>to be clicked link</a>
any help will be appriciated

Recommended Answers

All 4 Replies

Assuming that you are using the vb.net webbrowser, read on.
If this is for a login to a website, the link should have an Id. For example, using the following html page to navigate to,

<html><head><title>Untitled Page</title></head>
<body>
<a href="http://www.daniweb.com" id="myLink">to be clicked link</a>
</body>
</html>

and using the following code to get the proper link by id,

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        For Each link As HtmlElement In WebBrowser1.Document.Links
            If link.Id = "myLink" Then
                WebBrowser1.Navigate(link.GetAttribute("href"))
                Exit For
            End If
        Next
    End Sub

my webbrowser navigates to http://www.daniweb.com.

ya....that worked out.thank you...and sorry for the late reply.

When I run this, I get the following error: NullReferenceException was unhandled by user code - Object reference not set to an instance of an object. Do I need to declare something to make it work?

How about something like this how do you get the ID to be CLICK

<span style="display: inline;" class="v2"><a href="javascript:void(0)" id="My-Link">CLICK ME</a> <span style="font-weight: bold;" class="blpz">2.5</span> ETC </span>

Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.