Jump to content

problem with _IEquerySelectorAll() or ObjEvent ?


Recommended Posts

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
Link to comment
Share on other sites

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

×
×
  • Create New...