How can I get the full ID from an element with a token or a numric ID at the end, Something like this but VB.NET didn't seem to handle the querySelector the same way.
Javascript getElementById base on partial string
eg.
How can I get the full ID from an element with a token or a numric ID at the end, Something like this but VB.NET didn't seem to handle the querySelector the same way.
Javascript getElementById base on partial string
eg.
The solution for you is:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim wb1 As WebBrowser = New WebBrowser
Dim resultElements As List(Of HtmlElement) = New List(Of HtmlElement)
Dim processElement As Action(Of HtmlElement) = Sub(element As HtmlElement)
Dim elementID As String = element.GetAttribute("id")
If Len(elementID) > 0 Then
Console.WriteLine(elementID)
End If
'You can change this with your conditions
If elementID IsNot Nothing AndAlso
elementID.EndsWith("_01") AndAlso
resultElements.IndexOf(element) = -1 Then
resultElements.Add(element)
End If
'Or put here other conditions
'If elementName IsNot Nothing AndAlso elementName.StartsWith("01_ABCD") AndAlso resultElements.IndexOf(element) = -1 Then resultElements.Add(element)
If element.Children IsNot Nothing AndAlso element.Children.Count > 0 Then
For Each children In element.Children
processElement(children)
Next
End If
End Sub
AddHandler wb1.DocumentCompleted, Sub(senderWb As Object, eWb As WebBrowserDocumentCompletedEventArgs)
Dim allElements = wb1.Document.All
If allElements IsNot Nothing And allElements.Count > 0 Then
For Each element As HtmlElement In allElements
processElement(element)
Next
End If
' Here You have all your elements with custom ID condition
If resultElements.Count > 0 Then
For Each okElement As HtmlElement In resultElements
Console.WriteLine(okElement.GetAttribute("id"))
Next
End If
End Sub
wb1.Navigate("http://stackoverflow.com")
End Sub
Take me informed :)