Question Application to click a link on WebBrowser1 from Form

andyboot

New member
Joined
Nov 27, 2008
Messages
1
Programming Experience
3-5
Hi There,

In the middle of building an application and ripping my hair out trying to get this darn area of the application to work.

All I need the script to do is :-
1. Find the FIRST <a> tag which contains a Class="story_hide" attribute
2. Click the link

I've tried my hardest to get this to successfully work, now I have a headache.

Here's what my code resulted to before writing this thread:


VB.NET:
    Private Function GetElementByAttribValue(ByVal tagName As String, ByVal attribName As String, ByVal attribValue As String) As HtmlElement
        Dim elements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(tagName)

        For Each element As HtmlElement In elements
            If element.GetAttribute(attribName) = attribValue Then
                Return element
            End If
        Next

        Return Nothing
    End Function

VB.NET:
Private Sub Test()
Dim aElement As HtmlElement = GetElementByAttribValue("a", "class", "story_hide")
aElement.InvokeMember("click")
End Sub

Any help, much appreciated!!

Thanks,
Andy :)
 
The "class" attribute is accessed by "className", it's a special case probably because of some reserved word.
 
Back
Top