#Region Includes #include #EndRegion Includes Main() Func Main() Global $oIE = _IECreate("c:\test.html") MsgBox(0, "", _IE_XPath("//table[3]//tr/td[1]/table[2]//tr[2]/td[1]") ) EndFunc ;==>Main ; #FUNCTION# =================================================================== ; Name ..........: _IE_XPath ; Description ...: ; AutoIt Version : V3.3.0.0 ; Syntax ........: _IE_XPath($sXPath[, $sAttribute = "innerText"[, $sIE = "$oIE"]]) ; Parameter(s): .: $sXPath - ; supported @attributes: name | id ; supported functions: position() ; $sAttribute - Optional: (Default = "innerText") : ; $sIE - Optional: (Default = "$oIE") : ; Return Value ..: Success - string or object ; Failure - empty string ; @ERROR - 1 : No IE-Object ; 2 : Attribute not supported ; 3 : Error executing statement ; Author(s) .....: Thorsten Willert ; Date ..........: Wed Jan 06 14:17:56 CET 2010 ; Version .......: 0.11 ; ============================================================================== Func _IE_XPath($sXPath, $sAttribute = "innerText", $sIE = "$oIE") If Not Execute( "IsObj(" & $sIE & ")" ) Then Return SetError(1,0,"") Local $a = StringSplit($sXPath, "/") Local $aTMP, $pos, $ind, $seg Local $sElement = $sIE & ".document", $sSel = "getElementsByTagName" For $i = 1 To $a[0] $ind = 0 $seg = StringRegExpReplace($a[$i], '(.*?)\[.*?\]', '$1') If StringInStr($a[$i], "[") Then $ind = StringRegExpReplace($a[$i], '.*?\[\s*(\d+)\s*\]', '$1') - 1 EndIf If StringInStr($a[$i], "@") Then $pos = StringRegExpReplace($a[$i], '.*?\[.*?position\s*\(\)\s*=\s*(\d+).*?\]', '$1') -1 If $pos = -1 Then $pos = 0 $aTMP = StringRegExp($a[$i], '.*?@(\w+)\s*=\s*(''|")(\w+)\2', 3) Switch $aTMP[0] Case "id" $sSel = "getElementById" $sElement &= StringFormat(".%s('%s')", $sSel, $aTMP[2]) Case "name" $sSel = "getElementsByName" $sElement &= StringFormat(".%s('%s').item(%s)", $sSel, $aTMP[2], $pos) Case Else Return SetError(2,0,"") EndSwitch Else If $seg Then $sElement &= StringFormat(".%s('%s').item(%s)", $sSel, $seg, $ind) EndIf Next If $sAttribute Then $sElement &= "." & $sAttribute ConsoleWrite("_IE_XPath: " & $sElement & @CRLF) Local $r = Execute($sElement) If @error Then Return SetError(3,0,"") Return $r EndFunc ;==>_IE_XPath