cetipabo

problem with _IEquerySelectorAll() or ObjEvent ?

3 posts in this topic

#1 ·  Posted (edited)

Hello,
i'm trying to use this UDF _IEquerySelectorAll() to check if i clicked a button in a web page.

here is the index.html:

Spoiler

 

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>LIVEBOX INFOS JS</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    
    <style>
        tab-content {
            font-family: 'courier new', sans-serif;
        }
        .custom-container {
          padding: 16px 16px 16px 16px;
        }
        .nav-tabs{
          color:#000 !important;
        }

        .nav-tabs > li.active > a:focus,
        .nav-tabs > li > a:hover{
            color:#ff8700 !important;
        }

        .nav-tabs > li > a{
          color:#000 !important;
        }
    </style>
    
  </head>
<body>
<br>
<div class="custom-container">
    <div class="row">
        <div class="col-xs-3">
            <div class="panel panel-default">
                <div class="panel-body">
                    <form name="loginForm">
                      <div class="form-group">
                        <label for="user">IP Livebox:</label>
                        <input type="ip" class="form-control input-sm" id="ip" name="ip" value="192.168.1.1">
                      </div>
                      <div class="form-group">
                        <label for="user">Utilisateur:</label>
                        <input type="text" class="form-control input-sm" id="username" name="username" value="admin" disabled>
                      </div>
                      <div class="form-group">
                        <label for="pwd">Mot de passe:</label>
                        <input type="password" class="form-control input-sm" id="pwd" name="password" value="" autocomplete="off">
                      </div>
                      <h3><button type="button" class="btn btn-sm btn-default">Connexion</button>  <span class="label label-danger"><span class="glyphicon glyphicon-off" aria-hidden="true"></span></span></h3>
                    </form>
                </div> <!-- panel-body -->
                
            </div> <!-- panel -->
            <div class="panel panel-default">
                <div class="panel-body">
                <span class="text-danger">Les données écrites en rouge sont personnelles et ne doivent pas être postées sur internet.</span>
                </div> <!-- panel-body -->
            </div> <!-- panel -->
        </div> <!-- col -->
        
        <div class="col-xs-9">
            <ul class="nav nav-tabs">
              <li class="active"><a data-toggle="tab" href="#DeviceInfo">DeviceInfo</a></li>
              <li><a data-toggle="tab" href="#Mibs">Mibs</a></li>
              <li><a data-toggle="tab" href="#DSLstats">DSLstats</a></li>
              <li><a data-toggle="tab" href="#WANstatus">WANstatus</a></li>
              <li><a data-toggle="tab" href="#Wifi">Wifi</a></li>
              <li><a data-toggle="tab" href="#Services">Services</a></li>
              <li><a data-toggle="tab" href="#Voip">Voip</a></li>
            </ul>
            
            <div class="tab-content">
                <div id="DeviceInfo" class="tab-pane fade in active">
                    <br><pre>DeviceInfotxt</pre>
                </div>
                <div id="Mibs" class="tab-pane fade">
                    <br><pre>Mibstxt</pre>
                </div>
                <div id="DSLstats" class="tab-pane fade">
                    <br><pre>DSLstatstxt</pre>
                </div>
                <div id="WANstatus" class="tab-pane fade">
                    <br><pre>WANstatustxt</pre>
                </div>
                <div id="Wifi" class="tab-pane fade">
                    <br><pre>Wifitxt</pre>
                </div>
                <div id="Services" class="tab-pane fade">
                    <br><pre>Servicestxt</pre>
                </div>
                <div id="Voip" class="tab-pane fade">
                    <br><pre>Voiptxt</pre>
                </div>
            </div>
        </div> <!-- col -->
        
    </div> <!-- Row -->


</div> <!-- container -->

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>

</html>
 

 

and this is my autoit script including the _IEquerySelectorAll() function (modified by mLipok) :

Spoiler
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>


$oIE = _IECreateEmbedded()
$html_GUI = GUICreate("test", 820, 530)
$Browser = GUICtrlCreateObj($oIE, -1, -1, 820, 540)

_IENavigate($oIE, @scriptdir & "/index.html")
GUISetState(@SW_SHOW, $html_GUI)

$oDoc = _IEDocGetObj($oIE)
$oButton = _IEquerySelectorAll($oDoc,'button', 0)
ObjEvent($oButton, "_Evt_")


Func _Evt_onClick()
    msgbox(0,"","button clicked")
EndFunc


While 1
    ;Fermeture application si on clique sur la croix
    $nMsg = GUIGetMsg()
        if ($nMsg = $GUI_EVENT_CLOSE) then
            exit
        EndIf
WEnd








Func _IEquerySelectorAll(ByRef $oDoc, $sQuery, $iItemIndex = Default)
    If Not IsObj($oDoc) Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidDataType & " Invalid DataType" & @LF)
        Return SetError($_IEStatus_InvalidDataType, 1, 0)
    ElseIf Not __IEIsObjType($oDoc, "browserdom") Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidObjectType & " Invalid ObjectType" & @LF)
        Return SetError($_IEStatus_InvalidObjectType, 2, 0)
    ElseIf Not IsNumber($iItemIndex) And $iItemIndex <> Default Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Index" & @LF)
        Return SetError($_IEStatus_InvalidValue, 3, 0)
    ElseIf $iItemIndex = Default Or $iItemIndex >= 0 Then
        Local $oTemp = Null
        If __IEIsObjType($oDoc, "documentcontainer") Then
            $oTemp = _IEDocGetObj($oDoc)
            ConsoleWriteError("--> _IEDocGetObj Error: " & @error & " Ext: " & @extended & @LF)
            If @error Then Return SetError(@error, @extended, 0)
        Else
            $oTemp = $oDoc
        EndIf
        Local $oClassColl = $oTemp.querySelectorAll($sQuery)
        If @error Then
            ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IESTATUS_GeneralError & " GeneralError1: " & @error & @LF)
            Return SetError($_IESTATUS_GeneralError, 3, 0)
        ElseIf (Not IsObj($oClassColl)) Or $oClassColl = Null Or $oClassColl.length = 0 Then
            ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_NoMatch & " NoMatch" & @LF)
            Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both
        Else
            If $iItemIndex = Default Then
                Return SetError($_IEStatus_Success, $oClassColl.length, $oClassColl)
            ElseIf $iItemIndex > $oClassColl.length Then
                ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Value" & @LF)
                Return SetError($_IEStatus_InvalidValue, $oClassColl.length, 0)
            Else
                $oItem = $oClassColl.Item($iItemIndex)
                If @error Then
                    ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IESTATUS_GeneralError & " GeneralError2: " & @error & @LF)
                    Return SetError($_IESTATUS_GeneralError, 3, 0)
                ElseIf (Not IsObj($oItem)) Or $oItem = Null Then
                    ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_NoMatch & " NoMatch Index: " & $iItemIndex & @LF)
                    Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both
                Else
                    Return SetError($_IEStatus_Success, 0, $oItem)
                EndIf
            EndIf
        EndIf
    Else
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Value: " & $iItemIndex & @LF)
        Return SetError($_IEStatus_InvalidValue, 3, 0)
    EndIf
EndFunc   ;==>_IEquerySelectorAll

; User's COM error function.
; After SetUp with ObjEvent("AutoIt.Error", ....) will be called if COM error occurs
Func _User_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_User_ErrFunc

 


well, so i'm supposed to see a msgbox when i click the button, but nothing happens...

Can someone help me please ? something should be wrong here:
 

$oDoc = _IEDocGetObj($oIE)
$oButton = _IEquerySelectorAll($oDoc,'button', 0)
ObjEvent($oButton, "_Evt_")


Func _Evt_onClick()
    msgbox(0,"","button clicked")
EndFunc

 

Edited by cetipabo

Share this post


Link to post
Share on other sites



#2 ·  Posted

Anything useful appearing in the SciTE output window when you run the script?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

unfortunately no...

this is what i have in the output

Quote

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\...\Desktop\Livebox\LiveboxInfov2\lbinfo2.0.1.au3" /UserParams    
+>17:05:14 Starting AutoIt3Wrapper v.15.729.1555.1 SciTE v.3.6.0.0   Keyboard:0000040C  OS:WIN_10/  CPU:X64 OS:X64    Environment(Language:040C)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\...\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\kiki\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.1)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\...\Desktop\Livebox\LiveboxInfov2\lbinfo2.0.1.au3
+>17:05:14 AU3Check ended.rc:0
>Running:(3.3.14.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\...\Desktop\Livebox\LiveboxInfov2\lbinfo2.0.1.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

 

Edited by cetipabo

Share this post


Link to post
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

  • Similar Content

    • Chimp
      By Chimp
      Hello and happy new Year to everybody!
      I'm trying to catch some events occuring within a browser control by simply using the ObjEvent() function.
      I think I'm not using that function in a proper way since some events are captured, while other are not.
      more precisely, events like those listed in this page are working:
      https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx
      while other events listed in other "interfaces", as in the following links, does not works.
      https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx
      For exemple, Here I would like to catch events like "DragOver" and/or "Drop" fired while dragging the image on the web control, but I'm not been able to obtain a result.
      Those events are listed in the HTMLDocumentEvents4 interface or also in the HTMLImgEvents interface, but I failed to use them.
      Any hint that can help to see what I'm doing wrong, or even better that can show how to achieve the result by using the ObjEvent() function (if it's possible?) is welcome.
      Thanks a lot.
      Here is the simple script that I'm using for my tests:
      #include <GUIConstantsEx.au3> #include <string.au3> ; read html page from bottom of this script ; and write it to a file on disk for later ; usage by the $oIE.navigate CreateHtmlPage() Example() Exit Func Example() Local $hGUIMain = GUICreate("Event Test", 540, 400) ; We generate the Browser Control... Global $oIE = ObjCreate("Shell.Explorer.2") ; and we embed it into the AutoIt GUI $hIE = GUICtrlCreateObj($oIE, 5, 5, 530, 390) GUISetState() ;Show GUI ; load in the browser our previously created web page $oIE.navigate('file:///' & @ScriptDir & '\Page.html') Do ; wait for document Sleep(250) $oDocument = $oIE.document Until IsObj($oDocument) $oDocument.execCommand("Refresh") ; --- Setup catch of events --- Local $oEventObjects[2] $oImage = $oDocument.getElementById('drag1') ; Object reference to The image on the page ; https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx ; HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc ; ObjEvent() "Handles incoming events from the given Object." ; ObjEvent($oParam1, $sParam2 [,$sParam3]) ; Parameters ; $oParam1 A variable containing an Object from which you want to receive events ; ; $sParam2 The prefix of the functions you define to handle receiving events. ; The prefix is appended by the Objects method name. ; ; $sParam3 "interface name" [optional] name of an Event interface to use. ; Note: It must be a supported as outgoing for the Object AND it must be of type DISPATCH. ; Using third parameter as "HTMLDocumentEvents2" as event interface, or even leaving it blank, ; is the only way by which I've been able to catch some events from the browser control ; OK, events listed here are catched --> https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx $oEventObjects[0] = ObjEvent($oDocument, "IEEvent2_") ;, "HTMLDocumentEvents2") ; when I try to catch events fired by the Image dragged on the web page ; following attempts do not work (no event is captured and passed to AutoIt) ; $oEventObjects[1] = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2") ; $oEventObjects[1] = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents4") ; $oEventObjects[1] = ObjEvent($oImage, "IEEvent2_", "HTMLDocumentEvents2") ; $oEventObjects[1] = ObjEvent($oImage, "IEEvent2_") $oEventObjects[1] = ObjEvent($oImage, "IEEvent2_", "HTMLImgEvents2") ; ----------------------------- ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; the end For $i = 0 To UBound($oEventObjects) - 1 $oEventObjects[$i].Stop ; Tell IE we don't want to receive events. $oEventObjects[$i] = 0 Next $oEventObject = 0 ; Kill the Event Object $oIE = 0 ; Remove IE from memory (not really necessary). GUIDelete($hGUIMain) ; Remove GUI EndFunc ;==>Example ; below function should be fired by events ; occurred in the browser's objects ; --- events management zone --- Volatile Func IEEvent2_onClick($oEvent) ConsolePrint("mouse click:") EndFunc ;==>IEEvent2_onClick Volatile Func IEEvent2_onDblClick($oEvent) ConsolePrint("mouse DoubleClick:") EndFunc ;==>IEEvent2_onDblClick ; Drag related events Volatile Func IEEvent2_onDragstart($oEvent) ConsolePrint("Drag action started") EndFunc ;==>IEEvent2_onDragstart ; --- following events are not catched --- ??? Volatile Func IEEvent2_onDragOver($oEvent) ConsolePrint("DragOver event") EndFunc ;==>IEEvent2_onDragOver Volatile Func IEEvent2_onDrop($oEvent) ConsolePrint("Drop action performed ") EndFunc ;==>IEEvent2_onDrop ; ------------------------------ Func ConsolePrint($sMsg) ConsoleWrite($sMsg & @CRLF) EndFunc ;==>ConsolePrint Func CreateHtmlPage() Local $sStart = @LF & "#cs;HTML" Local $sEnd = "#ce;HTML" & @CR Local $aArray = _StringBetween(FileRead(@ScriptFullPath), $sStart, $sEnd) Local $sPage = @ScriptDir & '\Page.html' Local $hFile = FileOpen($sPage, 2) ; $FO_OVERWRITE (2) = Write mode (erase previous contents) FileWrite($hFile, $aArray[0]) FileFlush($hFile) FileClose($hFile) EndFunc ;==>CreateHtmlPage ; example got from here: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop2 #cs;HTML <!DOCTYPE HTML> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <style> #div1, #div2 { float: left; width: 214px; height: 214px; margin: 5px; padding: 10px; border: 1px solid black; } </style> <script> function allowDrop(ev) {ev.preventDefault();} function drag(ev) {ev.dataTransfer.setData("text", ev.target.id);} function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("text"); ev.target.appendChild(document.getElementById(data));} </script> </head> <body> <h2>Drag and Drop</h2> <p>Drag the image back and forth between the two div elements.</p> <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"> <img src="https://www.autoitscript.com/forum/uploads/monthly_2016_01/Chimp.jpg.688f81fa865450e2913b5dc2cb56215f.thumb.jpg.96a6bfa47c0fb8476f39aaf55ad68ed0.jpg" draggable="true" ondragstart="drag(event)" id="drag1" width="214" height="214"> </div> <div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"></div> </body> </html> #ce;HTML ;  
    • crzymnmchl
      By crzymnmchl
      I have e.g.
      Local $oIEEvents = ObjEvent(_IEGetObjById($oIE, "mylink"), "_MyLink_", "HTMLAnchorEvents2") working perfectly, but
      Local $oIEEvents = ObjEvent(_IEGetObjById($oIE, "future_btn"), "_Futurebtn_", "HTMLButtonElementEvents ") does not as ExtJS has not dynamically created the html yet. Is there anything in the IE API that would allow a callback to $oIE once the html is available?