954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

vb.net: auto click a link in a website

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 tag
eg:
to be clicked link
any help will be appriciated

codedude
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 1
 

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 toget 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 .

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

codedude
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 1
 

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?

NSchneid
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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

CLICK ME 2.5 ETC

Thanks :)

markjames2012
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: