1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is wrong with this?

Discussion in 'Visual Basic .NET' started by flann, Jul 7, 2012.

  1. flann

    flann Regular Member

    Joined:
    Jan 19, 2008
    Messages:
    208
    Likes Received:
    34
    This works:
    Code:
    Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
    
            For Each webpageelement As HtmlElement In allelements
    
    
                If webpageelement.InnerText = "word1 word2 word3" Then
                    webpageelement.InvokeMember("click")
                End If
            Next

    This not:
    Code:
    Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
    
            For Each webpageelement As HtmlElement In allelements
    
    
                If webpageelement.InnerText.Contains("word3") Then
                    webpageelement.InvokeMember("click")
                End If
            Next

    Why?
     
  2. openaidbh

    openaidbh BANNED BANNED

    Joined:
    Mar 3, 2012
    Messages:
    328
    Likes Received:
    320
    Try
    Code:
    If webpageelement.GetAttribute("innerText").Contains("word3") = True Then
         webpageelement.InvokeMember("click")
    End If
    
    Or
    Code:
    If webpageelement.InnerText.Contains("word3") = True Then
         webpageelement.InvokeMember("click")
    End If
    

    You have to ask if the Contains returns true or false.
     
  3. Chris22

    Chris22 Regular Member

    Joined:
    Sep 29, 2010
    Messages:
    400
    Likes Received:
    1,059
    Saying
    Code:
    If webpageelement.InnerText.Contains("word3") = True Then
    is just the same as saying
    Code:
    If webpageelement.InnerText.Contains("word3") Then
     
  4. openaidbh

    openaidbh BANNED BANNED

    Joined:
    Mar 3, 2012
    Messages:
    328
    Likes Received:
    320
    Flann, did either of the snippets I posted work for you?
     
  5. flann

    flann Regular Member

    Joined:
    Jan 19, 2008
    Messages:
    208
    Likes Received:
    34
    No, but no problem. i found a way around it ;)
    Thanks for the support!