Boa noite meu amigo, tudo bem?
Então, vamos lá: eu utilizo essa função, que permite a utilização do xpath:
Public Function getXPathElement(sXPath As String, objElement As Object) As HTMLBaseElement
Dim sXPathArray() As String
Dim sNodeName As String
Dim sNodeNameIndex As String
Dim sRestOfXPath As String
Dim lNodeIndex As Long
Dim lCount As Long
' Split the xpath statement
sXPathArray = Split(sXPath, "/")
sNodeNameIndex = sXPathArray(1)
If Not InStr(sNodeNameIndex, "[") > 0 Then
sNodeName = sNodeNameIndex
lNodeIndex = 1
Else
sXPathArray = Split(sNodeNameIndex, "[")
sNodeName = sXPathArray(0)
lNodeIndex = CLng(Left(sXPathArray(1), Len(sXPathArray(1)) - 1))
End If
sRestOfXPath = Right(sXPath, Len(sXPath) - (Len(sNodeNameIndex) + 1))
Set getXPathElement = Nothing
For lCount = 0 To objElement.ChildNodes().Length - 1
If UCase(objElement.ChildNodes().Item(lCount).nodeName) = UCase(sNodeName) Then
If lNodeIndex = 1 Then
If sRestOfXPath = "" Then
Set getXPathElement = objElement.ChildNodes().Item(lCount)
Else
Set getXPathElement = getXPathElement(sRestOfXPath, objElement.ChildNodes().Item(lCount))
End If
End If
lNodeIndex = lNodeIndex - 1
End If
Next lCount
End Function
E faço a chamada dela para o elemento que eu quero acessar, conforme abaixo:
Set ele = getXPathElement("/form/table/tbody/tr[1]/td[2]/input[1]", HTMLDoc.getElementById("Layer6"))
If Len(ele) > 0 Then
'Sua ação para o objeto
End If
Aqui vc informa o xpath do objeto: (getXPathElement("/form/table/tbody/tr[1]/td[2]/input[1]")
Aqui vc informa o ID do elemento a ser acessado: (HTMLDoc.getElementById("Layer6")))
Não sei se expliquei bem. Conseguiste entender?
