none
WebBrowser click RRS feed

  • Question

  • Hello, im trying to do click in webbrowser.

    I need to check if href = #country-ae and if yes i need to click in checkbox button

    Checkbutton not checked

    Checkbutton checked

        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
    
            For Each webpageelement As HtmlElement In allelements
                If webpageelement.GetAttribute("href").Contains("#country-ae") Then
                    If webpageelement.GetAttribute("className") = "fa fa-fw fa-square-o" Then
                        webpageelement.InvokeMember("click")
                    End If
                End If
            Next
        End Sub

    What is wrong?




    • Edited by extream87 Friday, March 3, 2017 8:54 PM
    Thursday, March 2, 2017 6:20 PM

Answers

  • Hi extream87,

    Based on your description, I can see that your HEML has three layers,

    <a………..
    
       <span……..
    
         <i……./i>
    
         /span>
    
      </a>
    

    So you can use HtmlElementCollection.Childern property to get className, I modify the code you provide, please refer to.

    Code sample:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    
            Dim allelements As HtmlElementCollection = webBrowser1.Document.All
    
    
            For Each webpageelement As HtmlElement In allelements
    
                If webpageelement.GetAttribute("href").Contains("country-ae") Then
    
    
                    Dim child As HtmlElement = webpageelement.Children(0).Children(0)
    
    
                    If child.GetAttribute("className") = "fa fa-fw fa-square-0" Then
    
                        webpageelement.InvokeMember("click")
    
                    End If
    
    
                End If
    
            Next
    
    End Sub
    

    Hope it is helpful to you.

    Best Regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by extream87 Friday, March 3, 2017 8:54 PM
    Friday, March 3, 2017 6:32 AM
    Moderator