Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27512

VS 2010 Simulating a link click

$
0
0
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.

Name:  Error.JPG
Views: 178
Size:  14.8 KB

P.S. I need only click simulation.
Process.Start("http://www.mysite2.com/") is not a solution
Attached Images
 

Viewing all articles
Browse latest Browse all 27512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>