How to take the text from a Div Class and put it inside a Label?
I'm trying to grab 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 Attempt
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 found that on the page there are several "Info" classes...
This code worked, but brought another result, beyond what was expected...
Dim theElementCollection As HtmlElementCollection
theElementCollection = 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 which also it has the "info" class.
<div class="msg"><div class="info">OMG/BTC and OMG/ETH OmiseGO markets added</div>
1
Author: Sérgio Wilker, 2017-12-05
1 answers
What you need to do is use an xpath query to specifically select the node you want.
This English StackOverflow question shows you how to use xpath with the .NET webbrowser (it's in C#, but it's easy to understand).
If you do not know how to use xpath, see this documentation.
0
Author: Gabriel, 2017-12-07 23:44:33