Jump to content
Sign in to follow this  
Jules

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

Recommended Posts

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By roeselpi
      hello again,
      it has been a long time since i have been here and a long time since i last used autoit. ever so often when the time allows me to, then i follow up on an idea that i had a long time ago. i have done all the work on paper but now it is up to writing it in autoit and i keep stumbling over many little issues here and there. sometimes after a few days i will try again and get a step further but sometimes it just will not help no matter how long i try and think about a solution. for most of you it will be the basics but for me it is not all that easy, but at least i give it a try.
      right, down to business:
      here is my code:
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> ; ; PART 1: define replacements and check with msgbox ; Global $y, $z $y = "Yes" $z = "No" MsgBox(0,"replacements", $y & @CRLF & $z) ;the replacements in a message box ; ; PART 2: set the texts and check via console and msgbox ; Global $my1string = "abab" ;the first specified text MsgBox(0,"my1string", $my1string) ;the message box to output the first specified text Global $my2string = "icic" ;the second specified text MsgBox(0,"my2string", $my2string) ;the message box to output the second specified text ; ; PART 3: transform the strings to individual arrays ; $my1array = StringSplit($my1string, "") $my1array[0] = "" _ArrayDelete($my1array, 0) _ArrayDisplay($my1array, "my1array") ;the display of the first specified array $my2array = StringSplit($my2string, "") $my2array[0] = "" _ArrayDelete($my2array, 0) _ArrayDisplay($my2array, "my2array") ;the display of the first specified array ; ; PART 4: create an empty array for filling ; Global $OutputArray[4] $OutputArray[0] = "" _ArrayDisplay($OutputArray, "OutputArray") ;the display of the first specified array ; ; PART 5: compare & fill empty OutputArray with data after evaluation ; Global $i, $j, $k For $i = 0 to UBound($my1array) -1 For $j = 0 to UBound($my2array) -1 For $k = 0 to UBound($OutputArray) -1 If $my1array[$i] = "a" And $my2array[$j] = "i" Then $OutputArray[$k] = $y Else $OutputArray[$k] = $z EndIf Next Next Next _ArrayDisplay($OutputArray, "OutputArray") ;the display of the Newly filled Array In "Part 2" i make a string that is converted to an array in "Part 3" ... Now, I know that "a" and "i" are always in the exact same spot in both arrays and so i wanted to compare this and make a further array to document my findings by saying "yes" or "no" ... however my new array keeps saying just "no" allthough i can clearly see and know that it should say:
      yes no yes no my guess is that there is something wrong within my for-loops and that the counting is somehow "off" i guess that when the first for-loop is finished it reaches the second whilst the second for-loop is checking the first which would explain why it always says "no" instead of seeing the obvious.
      so my question would be: what is wrong with my for-loop? or where am i making an error that ultimately gives me the wrong results?
      help is much appreciated.
      kind regards
      roeselpi
       
       
      PS: sorry for my not so great english spelling ... stupid german sitting here trying out intermediate english skills.
    • By Jangal
      Hello friends
      This app is slow
      How to increase its speed?
       
      #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2]  = [[1, "google"],[2,"hello"]]


        Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res)   for $sWord in $res     $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2)     ;MsgBox(0,0,$iIndex)     if $iIndex == -1 Then         Local $aFill = [[0,$sWord]]         _ArrayAdd($aWord,$aFill)        ;      Else         $aWord[$iIndex][0] +=1     EndIf   Next _ArrayDisplay($aWord)

      1.txt
    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
×
×
  • Create New...