Jump to content

IE9 and 10 Recording


jdelaney
 Share

Recommended Posts

Here are my initial steps to automating IE9 and 10 recording...there are still many issues, but the principles are here...

Known issue: the <script> data is appended, so reloads will remove it...need to continually append it back in

Navigation can cause the node to disappear quicker than all the attributes can be picked up...the fix will be to only grab certain attributes

Div data is hard to grab with a click...but if you click and drag on div text, everything works fine...

Please try it out, and provide suggestions.

The next step would be to logically create script based on the data output.

#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
Global $oIE = _IECreate("[url="http://www.autoitscript.com/forum/"]http://www.autoitscript.com/forum/[/url]")
Global $hwnd = _IEPropertyGet($oIE, "hwnd")

_IELoadWait($oIE)
$oObj = $oIE.document.createElement("script")
$oscript = $oIE.document.body.appendChild($oObj)
$AlertFunction = "document.onclick = myClickListener;" & @CRLF & _
"function myClickListener(e)" & @CRLF & _
 "{" & @CRLF & _
 "var eventIsFiredFromElement;" & @CRLF & _
 "if(e==null)" & @CRLF & _
 "{" & @CRLF & _
 "// I.E." & @CRLF & _
 "eventIsFiredFromElement = event.srcElement;" & @CRLF & _
 "}" & @CRLF & _
 "else" & @CRLF & _
 "{" & @CRLF & _
 "// Firefox" & @CRLF & _
 "eventIsFiredFromElement = e.target;" & @CRLF & _
 "}" & @CRLF & _
'alert("Event is fired from element : " + eventIsFiredFromElement.nodeName);' & @CRLF & _
" }"
;~ var script = document.createElement("script");
;~ script.async = false;
;~ script.src = url;
;~ document.body.appendChild(script);

;~ $AlertFunction = 'alert("Event is fired from element : ");'
;~ $AlertFunction = "alert(""Event is fired from element"");"
;~ $oObj = $oIE.document.createElement("script")
;~ $oObj.text = $AlertFunction
;~ $oscript = $oIE.document.body.appendChild($oObj)
$oscript = $oIE.document.body.getElementsByTagName("script")
ConsoleWrite($oscript.length & @CRLF)
For $obj in $oscript
;~  $obj.text =$obj.text & $AlertFunction
 $obj.text = $AlertFunction & $obj.text
;~  $obj.type = "text/javascript"
;~  $obj.language = "java"
;~  ConsoleWrite($obj.text & @CRLF)
Next
$text = _IEBodyReadHTML($oIE)
$text = _IEBodyWriteHTML($oIE, $text)

Local $gui = GUICreate("IE Dom", 800, 400, 0, 0)
; background picture
$button = GUICtrlCreateButton("Get Focused DOM obj Data", 5, 5)
$label = GUICtrlCreateInput("", 10, 35, 780, 350, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL))


GUISetState(@SW_SHOW)
While 1
 Local $msg = GUIGetMsg()
 Switch $msg
  Case $GUI_EVENT_CLOSE
   _IEQuit($oIE)
   Exit
  Case $button
   ;manual grab
   ControlSetText($gui, "", $label, OutputAttributes())
 EndSwitch
 ;dynamic grab
 If WinExists("Message from webpage") Then
  ConsoleWrite("messagebox!" & @CRLF)
  ControlSetText($gui, "", $label, OutputAttributes())
  WinWaitClose("Message from webpage")
 EndIf
WEnd
Func OutputAttributes()
 ControlSetText($gui, "", $label, "")
 WinActivate($hwnd)
 WinWaitActive($hwnd)
 $oElement = $oIE.document.activeElement
 Switch $oElement.nodename
  Case "A", "Img"
   $sReturn = "NodeName=[" & $oElement.nodename & "] NodeText=[" & $oElement.innertext & "]" & @CRLF & @CRLF
  Case "Input"
   ConsoleWrite("input" & @CRLF)
   $text = _IEFormElementGetValue($oElement)
   $sReturn = "NodeName=[" & $oElement.nodename & "] NodeText=[" & $text & "]" & @CRLF & @CRLF
  Case Else
   $oElement = $oIE.document.selection.createRange().parentElement()
   ConsoleWrite($oElement.nodename & @CRLF)
   $sReturn = "NodeName=[" & $oElement.nodename & "] NodeText=[" & $oElement.innertext & "]" & @CRLF & @CRLF
 EndSwitch

 If IsObj($oElement) Then
  For $iCounter = 0 To $oElement.attributes.length - 1
   $oAttribute = $oElement.attributes.item($iCounter)
   If StringLen($oAttribute.value) > 0 And $oAttribute.value <> "null" And $oAttribute.value <> "0" Then
    $sReturn &= "AttNAME=[" & $oAttribute.name & "]; AttValue=[" & $oAttribute.value & "]" & @CRLF
   EndIf
  Next
  Return $sReturn
 Else
  Return "Failed to find object"
 EndIf
EndFunc   ;==>OutputAttributes
Exit
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • 8 months later...

LOVE this! I was thinking of making something similar to this that would tell you what was needed to gain access to the specific element you clicked on. so if you clicked in an input box, it would tell you the name/ID of the input box and then tell you if it was in a Frame or form and what the names/IDs of those frames or forms were.

works great for me so far.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...