1,105,417 Community Members

vb.net: auto click a link in a website

Member Avatar
codedude
Newbie Poster
12 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
codeorder
Postaholic
2,027 posts since Aug 2010
Reputation Points: 197 [?]
Q&As Helped to Solve: 390 [?]
Skill Endorsements: 10 [?]
 
0
 

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.

Question Answered as of 3 Years Ago by codeorder
Member Avatar
codedude
Newbie Poster
12 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NSchneid
Newbie Poster
1 post since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
markjames2012
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: