[..] Javascript vs _IEFormGetCollection

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
DomVzl
Niveau 1
Niveau 1
Messages : 2
Enregistré le : mar. 15 avr. 2014 18:43
Status : Hors ligne

[..] Javascript vs _IEFormGetCollection

#1

Message par DomVzl »

Bonjour,
Je cherche à remplir un formulaire d'une page Web.
J'ai bien compris l'utilisation de la bibliothèque IE.au3, mais je reste coincé sur un "détail".
En effet, les fonctions fournies traites les "form" sans pb mais les pages que je souhaite alimenter sont écrites non pas en "form" classiques mais via du javascript. Ce qui, visiblement, ne me permet pas de récupérer les id ou nom des champs.

Comme je reste débutant, donc j'ai testé les scripts fournis dans l'aide pour voir que ce j'avais raté...
et surprise :
J'ai utilisé texto le script donné pour la fonction _IEFormGetCollection.
Le premier exemple sur Google fonctionne parfaitement.
Mais le 3ème sur http://www.autoitscript.com ne renvoie rien. Justement...
Si j'ai bien compris, c'est parce que la page est construite via du js et non en utilisant les "form" classiques.

C'est bien là le coeur de mon problème...

Une idée ?
D'avance merci.
Modifié en dernier par DomVzl le mer. 16 avr. 2014 10:15, modifié 1 fois.
Avatar du membre
jguinch
Modérateur
Modérateur
Messages : 2515
Enregistré le : lun. 14 févr. 2011 22:12
Status : Hors ligne

Re: Javascript vs _IEFormGetCollection

#2

Message par jguinch »

Boujour DomVzl, bienvenue sur le forum.
Tout d'abord, merci de modifier le titre de ton sujet afin qu'il respecte les règles de présentation d'un message.
Le script, ça fait gagner beaucoup de temps... à condition d'en avoir beaucoup devant soi !
lesolutionneur
Niveau 7
Niveau 7
Messages : 368
Enregistré le : ven. 09 déc. 2011 11:25
Status : Hors ligne

Re: [..] Javascript vs _IEFormGetCollection

#3

Message par lesolutionneur »

Il faudrait que tu nous donnes un code source HTML et ton code AutoIt qui ne fonctionne pas pour que l'on puisse t'aider.
Avatar du membre
jguinch
Modérateur
Modérateur
Messages : 2515
Enregistré le : lun. 14 févr. 2011 22:12
Status : Hors ligne

Re: [..] Javascript vs _IEFormGetCollection

#4

Message par jguinch »

L'exemple 3 de _IEFormGetCollection fonctionne très bien : il renvoie le nombre de formulaires (1) et le nom de chacun (0 si pas de nom)
Le script, ça fait gagner beaucoup de temps... à condition d'en avoir beaucoup devant soi !
DomVzl
Niveau 1
Niveau 1
Messages : 2
Enregistré le : mar. 15 avr. 2014 18:43
Status : Hors ligne

Re: [..] Javascript vs _IEFormGetCollection

#5

Message par DomVzl »

Bonjour,

jguinch : Oui, tu as raison, à force de chercher ce qui ne va dans mon code je trouve des erreurs là où il n'y en a pas. Autant pour moi.
Plus le temps passe et plus je me dis que ce doit être tellement énorme que je ne vois pas le truc qui coince...

lesolutionneur :
voici un premier exemple très simple : je veux lancer une recherche sur le site autoitscript.com :

Code : Tout sélectionner

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
Local $iNumForms = @extended
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
Local $oForm
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE, $i)
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.id)
Next

Local $oField_search = _IEFormElementGetObjByName($oForms, "s")
_IEFormElementSetValue($oField_search, "documentation autoit")
_IEFormSubmit($oForms)
;Send("{ENTER}")
 
L'id du form s'affiche bien, donc il l'a bien trouvé.
Mais impossible d'alimenter la zone de recherche ni de lancer la recherche par "submit" ou "send"

Le vrai prog que je souhaite faire c'est le suivant :

Code : Tout sélectionner

#include <IE.au3>
#include <MsgBoxConstants.au3>

Dim $url_enter = "mon_url.html"

Dim $username_ID = "username"
Dim $username_value = "toto"

Dim $pwd_ID = "password"
Dim $pwd_value = "tutu"



Local $oIE = _IECreate($url_enter)

Local $oForms = _IEFormGetCollection($oIE)
Local $oField_username = _IEFormElementGetObjByName($oForms, $username_ID)
_IEFormElementSetValue($oField_username, $username_value)

Local $oField_pwd = _IEFormElementGetObjByName($oForms,$pwd_ID)
_IEFormElementSetValue($oField_pwd, $pwd_value)

Local $oButton = _IEFormElementGetObjByName($oForms, "B1")
_IEAction($oButton, "click")


MsgBox(0,"Finish", "Process ended")
Le code source de la page :

Code : Tout sélectionner

<!-- Entrust TruePass 8.1 -->

<html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
        <title>User Authentication - Entrust Desktop Security Store User</title>
    </head>

    <script language="JavaScript">

        function browse()
        {
            apiAccess.entrustTruePassClientAPI.entrustTruePassToolkitShowLoadFileDialog("operationID", "entrustTruePassShowFileDialogEventListener", "parent.entrustTruePassGuiFrame", "Select a profile to log in to", ".epf");
        }

        // Callback function for file dialog display -- called once the user has selected a file or cancelled the dialog
        function entrustTruePassShowFileDialogEventListener(statusCode, operationID, fileName)
        {
            if (statusCode == 0){
                document.entrustform.username.value = fileName;
            }
        }

    </script>


    <body>
    
        <!-- This is a check if the Entrust TruePass API is present.
        This case (when an input page is loaded but the API is missing) indicates
        a undefined situation within the TruePassSample pages. 
        The index page of the TruePassSample will be loaded to the top to get a 
        proper state of the TruePassSample. -->
        <script language="JavaScript">
            if (parent.multiDomainConfiguration == "PRIMARYSITE") {
                apiAccess = parent;
            }
            else {
                apiAccess = top;
            }

            if (!(apiAccess.entrustTruePassClientAPI)) {
                apiAccess.document.location = "/GetAccess/ResourceList";
            }
        </script>
             
        <font face="Arial, Helvetica" size="2">
            <br>
                    <STRONG>Aviso a los usuarios con algún tipo de discapacidad visual, cognitiva o motriz:</STRONG> los servicios con certificado digital no cumplen las pautas de accesibilidad, lo que puede impedir un acceso correcto a los mismos. <a href="xxxx" target="_top">(Más información)</a>
            <br>
            <br>
      <br>
            <b>Autenticación de usuarios - Certificado SILCON</b>
            <br>
      <br>
            Por favor, seleccione el archivo .epf que contiene su certificado SILCON e introduzca la contraseña correspondiente a este certificado.
            
            <!--
                Most TruePass related forms contain sensitive data such as usernames and passwords.
                To prevent such sensitive data from being sent over to the webserver (and consequently
                showing up in the Web server's log file), steps must be taken to indicate to the browser
                that it should not submit the form data to the server - instead, the onSubmit Javascript
                handler must be used to call into the TruePass applet for processing the form data.
                The following security guidelines are recommended for all TruePass forms:
                    1. The internal default "onSubmit" EventHandler of the Web browser automatically sends the
                        content of a form as a query string in a HTTP GET request (the form data will be sent
                        over the net and show up in the Web server's log file). Make sure to disable the 
                        default "onSubmit" EventHandler under all circumstances by using the following statement:
                            onSubmit="entrustTruePassFunction(); return false;"
                        The command 'entrustTruePassFunction()' will be dispatched and 'return false' will be executed
                        regardless of the return value of 'entrustTruePassFunction()'.
                    2. Generate the form's submit button (or image) using the document.write() method of Javascript.
                        This prevents the form from having a submit button when Javascript is unavailable. In such 
                        cases, the <noscript> tag can be used to indicate to the end user that Javascript is unavailable.
                    3. A form that has just a single HTML input type element, is submitted by the browser even if 
                        a submit button is not present in the form. If it is necessary to have such a form, then the 
                        HTML code for the input type should be generated using Javascript, like in step 2 above.
                    4. Add the ACTION="https://0.0.0.0" attribute to the form definition. This is a non-Javascript
                        solution which prevents the form data from leaving the end user's machine under all circumstances.
            -->
            <form name="entrustform" ACTION="https://0.0.0.0" onSubmit="apiAccess.entrustTruePassClientAPI.entrustTruePassAuthenticateUser(document.entrustform); return false;">

                <!-- The names of the input fields must be "username", "password", "authenticationExtension"
                and "storeUsernameCheckbox". The authenticationExtension and the checkbox are optional
                but if they exist, the mentioned names are mandatory. -->
                <table border="0">
                    <tr>
                        <td><font face="Arial, Helvetica" size="2"><b>Archivo EPF:</b></font></td>
                        <td><input type="text" name="username" size="38"></td>
                        <td><input type="button" value= "Explorar" name="browseButton" onClick="browse();" ></td>
                        <script language="JavaScript">
                            if (apiAccess.entrustTruePassClientAPI.entrustTruePassGetLastUserProfileType() == "LOCAL_EPF") {
                                document.entrustform.username.value= apiAccess.entrustTruePassClientAPI.entrustTruePassGetLastUser();
                            }
                        </script>
                    </tr>

                    <tr>
                        <td><font face="Arial, Helvetica" size="2"><b>Contraseña:</b></font></td>
                        <!-- AUTOCOMPLETE = "off" will turn off the password autocomplete option-->
                        <td><input type="password" name="password" AUTOCOMPLETE="off" value="" size="38"></td>
                        <!-- Set the focus to the password or the username field -->
                        <script>
                            if (document.entrustform.username.value == "") {
                                // Set the focus to the username field if no username was read from the cookie
                                document.entrustform.username.focus();
                            }
                            else {
                                // Set the focus to the password field if a username is present
                                document.entrustform.password.focus();
                            }
                        </script>
                    </tr>

                    <tr>
                        <td></td>
                        <td><input type="checkbox" checked name="storeUsernameCheckbox">
                        <font face="Arial,Helvetica" size="2">Recordar usuario</font></td>
                    </tr>

                    <tr>
                        <td>
                        </td>
                        <td>
                            <br>
                            <script>
                                // The button triggers the Authenticate User function from the API
                                document.write('<input type="submit" value="Aceptar" name="B1">');
                            </script>
                            <noscript>
                                <font color="red">
                                    <br>
                                    <b>Error: Javascript debe estar habilitado para las operaciones de TruePass</b>
                                    <br>
                                </font></noscript>
                            <input type="reset" value="Cancelar" name="B2">
                        </td>
                    </tr>
                </table>
            </form>
      </font>
            <p>
    <font face="Arial, Helvetica" size="2">
            <br>
        Si no dispone usted de un Certificado SILCON,  consulte por favor el apartado de Certificados Digitales dentro de nuestra Sede Electrónica. 
    </font>     
            </p>
    </body>
</html>
 
C'est un site espagnol, il est un peu expurgé de certaines données... s'il y a besoin j'envoie en MP la véritable adresse...
Je précise juste, que, ce que je veux faire est évidement légal : aider des utilisateurs qui remplissent manuellement des formulaires pour télécharger des attestations PDF.... ils en ont parfois plusieurs centaines par jours !

D'avance merci.
Répondre