How to get the Text of a Div Class and Place inside a Label?

0

I'm trying to get the "value" inside the div to put inside a Label.

Div:

<div class="info">valor</div>

First Attempt

Variavel1 = WebBrowser1.Document.GetElementById("info").GetAttribute("innerText")

Label1.Text = Variavel1

Second Try

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
    If Element.OuterHtml.Contains("class") = "info" Then
       Variavel1 = Element.GetAttribute("innerText")
       Return
    End If
Next

Label1.Text = Variavel1

I discovered that on the page there are several "Info" classes ...

Thiscodeworked,butitbroughtanotherresultthanexpected...

DimtheElementCollectionAsHtmlElementCollectiontheElementCollection=WebBrowser1.Document.GetElementsByTagName("Div")
    For Each curElement As HtmlElement In theElementCollection
        If curElement.OuterHtml.Contains("info") Then
            Variavel1 = (curElement.GetAttribute("InnerText"))
        End If
    Next

Label1.Text = Variavel1

The result was the value of this Div that also has the class "info".

<div class="msg"><div class="info">OMG/BTC and OMG/ETH  OmiseGO markets added</div>
    
asked by anonymous 05.12.2017 / 01:35

1 answer

0

What you need to do is use an xpath query to specifically select the node you want.

This StackOverflow question in English shows how to use xpath with the .Net WebBrowser (it's in C #, but you can understand that).

If you do not know how to use xpath, see this documentation .

    
08.12.2017 / 00:44