Quantcast
Viewing all articles
Browse latest Browse all 27201

VS 2010 Simulating a link click

There is a part of an HTML code of my website www.mysite.com

Code:

<span id="my-footer">
  Visit my <a target="_blank" href="http://www.mysite2.com/">second website</a>
</span>

I need to write a code to get into website www.mysite.com and then to click to link with ID “my-footer” if it exists.
There is my code:

Code:

Private Sub btnURL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnURL.Click

        Dim webBrowser1 As New WebBrowser

        Dim myURL As String = "http://mysite.com"
        Dim myWebBrowser As String = "IExplore"

        Process.Start(myWebBrowser, myURL)

        webBrowser1.Navigate(New Uri(myURL))
        Thread.Sleep(1000)

        For Each ele As HtmlElement In webBrowser1.Document.Links

            If ele.GetAttribute("id") = "my-footer" Then

                ele.InvokeMember("click")

            End If
        Next

    End Sub

However, an error (see below) is generated after execution of the code.

Any suggestion will be appreciated.

Image may be NSFW.
Clik here to view.
Name:  Error.JPG
Views: 150
Size:  14.8 KB


P.S. I need only click simulation.
Process.Start("http://www.mysite2.com/") is not a solution
Attached Images
Image may be NSFW.
Clik here to view.
 

Viewing all articles
Browse latest Browse all 27201

Trending Articles