Jump to content

_IE Objects and catch JavaScript Response? Not Possible?


Recommended Posts

I recently try to automate a Website with _IE UDF and I don't find a way to interact with JavaScript response this is not possible? why?

Here is my point:
JavaScript run code locally and get a result, in order to pass that result to the Browser JavaScript send that response inside HTML tags, so why is not possible to catch that data?
Maybe I'm wrong or I have a miss concept.

For example:
- JavaScript with onclick event function make some request to know the direct url to download something.
- Pass this result to the Browser and then you got Open/Save Dialog.(here is passing that result like HTML right?)

So there is no object or way to catch that result when the JavaScript code send it to the Browser?

Regards
Alien.
 

Link to comment
Share on other sites

You can do something like this:

  1. Identify the java function responsable for "build" the url. You need to know that depending on how the url is "build" you will not be able to get the direct download link.
  2. Then modify the function and use the _IEHeadInsertEventScript.
  3. At the end of the modified function make an alert or a modification in the website html to show the url.
  4. You can also manually input the java in the addressbar.

This is just one method to make a java function spill the data you want.

 

Link to comment
Share on other sites

9 hours ago, MichaelHB said:

You can do something like this:

  1. Identify the java function responsable for "build" the url. You need to know that depending on how the url is "build" you will not be able to get the direct download link.
  2. Then modify the function and use the _IEHeadInsertEventScript.
  3. At the end of the modified function make an alert or a modification in the website html to show the url.
  4. You can also manually input the java in the addressbar.

This is just one method to make a java function spill the data you want.

 

Thanks you @MichaelHB
This is very interesting and look like a good way to do it, I run some small test to understand _IEHeadInsertEventScript
But I'm not good with Java Script, I can't identify the function that request the final link to download.

Anyways my question remains, there is no way to identify or read what the Script pass to the browser on the browser content?
I mean let say I want to see every internal HTTP request the internet explorer made and analyze all the html replies he got?

Regards
Alien.
 

Link to comment
Share on other sites

If the website you're using is secured enough - you won't be able to get the link. It's not difficult to create a dynamic page (in PHP or JSP for example) that checks the session and only after it validates that you are logged in, it lets you access data. And you can monitor your side but not the server side. If this is for that subtitle page i remeber that i saw some jsp functions that send data to other server, validates it and only then you get the download. I'm not saying that is impossible, just not that simple.

You can manage the dialog "save file" easily with UIAutomation. Try this example, click on the download link and when the dialog shows, run this code from Larsj, and look if a control named "save" (i belive this will display as "Guardar" for you) will appear.

#include "CUIAutomation2.au3"

;~ Opt( "MustDeclareVars", 1 )
Opt( "WinTitleMatchMode", 2 )

Example()
Exit

Func Example()
  ; Window
  Local $hWindow = WinGetHandle( "The Blacklist" ) ; *** Put the title of the window here ***
  If Not $hWindow Then Return ConsoleWrite( "Window handle ERR" & @CRLF )
  ConsoleWrite( "Window handle OK" & @CRLF )

  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "UI Automation object ERR" & @CRLF )
  ConsoleWrite( "UI Automation object OK" & @CRLF )

  ; Get UI Automation element from window handle
  Local $pWindow, $oWindow
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  ; Note that $oWindow is an AutomationElement object
  ; Search for $dtagIUIAutomationElement in CUIAutomation2.au3 to see which methods can be used
  If Not IsObj( $oWindow ) Then Return ConsoleWrite( "Automation element from window ERR" & @CRLF )
  ConsoleWrite( "Automation element from window OK" & @CRLF )

  #cs
  ; Condition to find text controls
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "Property condition ERR" & @CRLF )
  ConsoleWrite( "Property condition OK" & @CRLF )
  #ce

  ; Condition to find custom controls
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_SplitButtonControlTypeId, $pCondition )
  ; You can use any of the ControlTypeIds in CUIAutomation2.au3 (search for ControlTypeId)
  If Not $pCondition Then Return ConsoleWrite( "Property condition ERR" & @CRLF )
  ConsoleWrite( "Property condition OK" & @CRLF )

  ; Find custom controls
  Local $pUIElementArray, $oUIElementArray, $iElements
  $oWindow.FindAll( $TreeScope_Descendants, $pCondition, $pUIElementArray )
  ; You can use any of the TreeScope constants in CUIAutomation2.au3 (search for TreeScope)
  $oUIElementArray = ObjCreateInterface( $pUIElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oUIElementArray.Length( $iElements )
  If Not $iElements Then Return ConsoleWrite( "Find controls ERR" & @CRLF )
  ConsoleWrite( "Find controls OK" & @CRLF )

  ; Print custom control info
  Local $pUIElement, $oUIElement
  For $i = 0 To $iElements - 1
    ConsoleWrite( @CRLF )
    $oUIElementArray.GetElement( $i, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    ConsoleWrite( "Index     = " & $i & @CRLF & _
                  "Name      = " & GetCurrentPropertyValue1( $oUIElement, $UIA_NamePropertyId ) & @CRLF & _
                  "Class     = " & GetCurrentPropertyValue1( $oUIElement, $UIA_ClassNamePropertyId ) & @CRLF & _
                  "Ctrl type = " & GetCurrentPropertyValue1( $oUIElement, $UIA_ControlTypePropertyId ) & @CRLF & _
                  "Ctrl name = " & GetCurrentPropertyValue1( $oUIElement, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  "Value     = " & GetCurrentPropertyValue1( $oUIElement, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                  "Rectangle = " & GetCurrentPropertyValue1( $oUIElement, $UIA_BoundingRectanglePropertyId ) & @CRLF & _
                  "Handle    = " & Hex( GetCurrentPropertyValue1( $oUIElement, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF )
                  ; You can add any of the PropertyIdIds in CUIAutomation2.au3 (search for PropertyId)
  Next

EndFunc

Func GetCurrentPropertyValue1( $obj, $id )
  Local $tVal
  $obj.GetCurrentPropertyValue( $id, $tVal )
  If Not IsArray( $tVal ) Then Return $tVal
  Local $tStr = $tVal[0]
  For $i = 1 To UBound( $tVal ) - 1
    $tStr &= "; " & $tVal[$i]
  Next
  Return $tStr
EndFunc

This above will show you the propertys and then you can use this to invoke (click the save button). You need to put this code in the "For" loop that prints the control info. Just an example.

Local $sSave = "Guardar" ; *** Check if this is the same as in the button name output you want to click ***
If GetCurrentPropertyValue1( $oUIElement, $UIA_NamePropertyId ) = $sSave Then
    MsgBox(0, "", "")
    Local $pInvoke, $oInvoke
    $oUIElement.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
    $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
    If Not IsObj( $oInvoke ) Then Return ConsoleWrite( "Invoke object ERR" & @CRLF )
    ConsoleWrite( "Invoke object OK" & @CRLF )
    $oInvoke.Invoke()
EndIf

 

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...