Sign in to follow this  
Followers 0
Jules

_FFGetPosition gives error "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

3 posts in this topic

Hello :),

I am developing a script with AutoIt for Firefox, to automate performance tests. I have a map, that I have to wait to be loaded, and then I have to click at the center of this map.

In order to do this, I get the position of the HTML element representing the map, then I perform a few calculations to find center coordinates. But I have a problem.

I use the FF.au3 library, and the function _FFGetPosition to get the coordinates. My function call is

$CoordCarte = _FFGetPosition(".getElementById('OpenLayers.Layer.Annotation_3_svgRoot')")

and AutoIt gives me this error :

"C:\Program Files\AutoIt3\Include\FF.au3" (1928) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Local $aRet[6] = [$aElement[0], $aElement[1], $aContent[0], $aContent[1], $aContent[2], $aContent[3]]
Local $aRet[6] = [$aElement[0], ^ ERROR

I checked the HTML id of the element, and it is correct (I checked in Firefox with Javascript console).

I really can't figure out what is my mistake. Could you help me please ?

 

If this can help you, here is my script (comments are in French) :

; ##########
; INCLUSIONS
; ##########
#include <Array.au3>
#include <FF.au3>
#include <String.au3>


; ##################
; PARAMETRES GLOBAUX
; ##################
Opt("SendKeyDownDelay",80) ; pas trop rapide pour éviter que des frappes soient perdues
Opt("WinTitleMatchMode", 3) ; Noms des fenêtres correspondant exactement
Opt("GUIEventOptions", 1)


; ################################################
; ######## FONCTIONS POUR TESTS DE PERF. #########
; ################################################

Func FaireUnTest()
   ; Faire un test de performance pour ArcMap
   ;
   ; Return :
   ; Une chaine de caractères avec les temps de chaque tâche, séparés par des point-virgules

   Local $LigneTemps = "" ; Contient le temps de chaque tâche, séparés par des point-virgules

   ; Démarrer Firefox
   _FFStart()

   ; Handle de la fenêtre Firefox ouverte
   $hFirefox = _FFWindowGetHandle()

   ; Connexion MozRepl
   _FFConnect()



   ; ###########################
   ; ###########################
   ; ######### TACHE 1 #########
   ; ###########################
   ; ###########################

   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ; Connexion au site de Carmen ;
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   ; Initialisation nouveau timer
   $hTimer = TimerInit()

   ; Aller à l'URL de Carmen et attendre son chargement
   _FFOpenURL("http://carmen.carmencarto.fr/179/OSUR.map#")

   ; Attendre le chargement de la carte
   AttendreChargementCarte()

   ; Ajout temps de la tâche
   $LigneTemps = $LigneTemps & ";" & TimerDiff($hTimer) / 1000

   ; ###########################
   ; ###########################
   ; ######### TACHE 2 #########
   ; ###########################
   ; ###########################

   ;;;;;;;;;;;;;;;;;;;;;
   ; Localiser 'ACHUN' ;
   ;;;;;;;;;;;;;;;;;;;;;

   ; Initialisation nouveau timer
   $hTimer = TimerInit()

   ; L'échelle avant le zoom
   $queryEchelle = ".getElementsByClassName('DescartesGraphicScale')[1].textContent"
   $EchelleAvantZoom = _FFCmd($queryEchelle)

   ; On écrit 'ACHUN' dans le champ de commune
   $InputCommune = _FFObjGet("combo2", "id")
   _FFObj($InputCommune, "value", "ACHUN")

   ; Il faut ensuite sélectionner l'élément 'ACHUN' dans la liste déroulante
   ControlSend($hFirefox, "", "", _StringRepeat("{TAB}", 27)) ; focus sur liste déroulante 'Commune'
   ControlSend($hFirefox, "", "", _StringRepeat("{DOWN}", 7)) ; sélection élément 'ACHUN'
   ControlSend($hFirefox, "", "", "{ENTER}") ; validation

   ; Clic bouton 'Localiser'
   _FFClick("button", "tag", 0)

   ; Attendre que le zoom soit fait (ie un changement d'échelle)
   While _FFCmd($queryEchelle) = $EchelleAvantZoom
   WEnd

   ; Attendre le chargement de la carte
   AttendreChargementCarte()

   ; Ajout temps de la tâche
   $LigneTemps = $LigneTemps & ";" & TimerDiff($hTimer) / 1000



   ; ###########################
   ; ###########################
   ; ######### TACHE 3 #########
   ; ###########################
   ; ###########################

   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ; Sélection d'une station  ;
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   ;########## NE COMPTE PAS DANS LES MESURES ##########

   ; Inputs 'x' et 'y' de la page web
   $InputX = _FFObjGet("x", "id")
   $InputY = _FFObjGet("y", "id")

   ; Saisie de la position géographique (dans la carte) de la station '04023310'
   _FFObj($InputX, "value", "747562")
   _FFObj($InputY, "value", "6667893")

   ; Centrage de la carte sur la station '04023310'
   ControlSend($hFirefox, "", "", _StringRepeat("{TAB}", 7)) ; focus sur bouton 'Centrer'
   ControlSend($hFirefox, "", "", "{ENTER}") ; validation

   ; On attend le chargement
   AttendreChargementCarte()

   ;########## LA SUITE COMPTE MAINTENANT POUR LES MESURES ##########


   ; Initialisation nouveau timer
   $hTimer = TimerInit()

   ; Clic bouton "Interroger les couches" (après navigation avec {TAB} car cela aurait ouvert une fenêtre non voulue)
   _FFClick("button", "tag", 9)


   ;$x = _FFObjGet("OpenLayers.Layer.Annotation_3_svgRoot", "id")
   ;MsgBox(0, $x, $x)
   ; Coordonnées de la carte, relativement à l'écran d'ordinateur
   $CoordCarte = _FFGetPosition(".getElementById('OpenLayers.Layer.Annotation_3_svgRoot')")


   ; Coordonnées coin supérieur gauche
   $XDebCarte = $CoordCarte[2]
   $YDebCarte = $CoordCarte[3]

   MsgBox(0, "$XDebCarte = ", $XDebCarte)
   MsgBox(0, "$YDebCarte = ", $YDebCarte)

   ; Coordonnées coin inférieur droit
   $XFinCarte = $XDebCarte + $CoordCarte[4]
   $YFinCarte = $YDebCarte + $CoordCarte[5]

   MsgBox(0, "$XFinCarte = ", $XDebCarte)
   MsgBox(0, "$YFinCarte = ", $YDebCarte)

   ; Coordonnées du centre de la carte, relativement à l'écran d'ordinateur
   $XMilieuCarte = ($XDebCarte + $XFinCarte) / 2
   $YMilieuCarte = ($YDebCarte + $YFinCarte) / 2

   MsgBox(0, "$XMilieuCarte = ", $XDebCarte)
   MsgBox(0, "$YMilieuCarte = ", $YDebCarte)

   ; Cliquer au milieu de la carte
   MouseClick("left", $XMilieuCarte, $YMilieuCarte, 1, 1)



EndFunc

FaireUnTest()


Func AttendreChargementCarte()
   ; Met le script en pause jusqu'au chargement complet
   ; de la carte de l'application Carmen

   ; Code JavaScript pour récupérer les images de la carte
   $imagesQuery = ".getElementsByClassName('olTileImage')"

   ; Le nombre d'images de la carte
   $NbImages = _FFCmd($imagesQuery & ".length")

   ; On attend que toutes les images de la carte soit chargées
   For $i = 0 To $NbImages - 1

      ; Le code JavaScript pour savoir si la i-ème image est chargée
      $imageCompleteQuery = $imagesQuery & "[" & $i & "].complete"

      ; Et on attend qu'elle soit chargée
      While Not _FFCmd($imageCompleteQuery)
      WEnd

   Next

EndFunc

 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I downloaded the most recent version, but I still have the same error.

To me, the _FFGetPosition function takes as argument a String containing Javascript code that returns an element from the DOM.

Edited by Jules

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • BOUNCER
      By BOUNCER
      I'm trying to get the output data from https://www.guilded.gg but it uses a web app that generates that output on the fly and this doesn't show up in the page source.
      Only in web inspector of each browser does this data show up. How do I read this data in autoit (equivalent to the web inspector)
       
      thank you
    • Pao
      By Pao
      Hello, I've recently updated from Firefox 50 to 54.0.1.
      My Autoit script that previously worked fine, now seems to have erratic problems.
      It's almost as if some Send() commands are sometimes skipped when dealing with the Firefox UI (it's still mostly fine on the actual pages).

      To temporarly fix the problem, I had to put some Sleep(200) pauses and avoid grouping keys together (e.g: TAB 2), but I'm not exactly sure about the correct way to deal with this..
      Could this be caused by the new multiprocess feature? (e10s)
      Are there better Autoit commands or rules that I should use?
       
    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!