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

    • rootx
      By rootx
      I write this script to compare to array, well Do you have a better way to do it?
      #include <Constants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $a = FileSelectFolder("seleziona cartella A",@ScriptDir) $fold_A = _FileListToArrayRec($a,"*",2,1,0,1) $b = FileSelectFolder("seleziona cartella B",@ScriptDir) $fold_B = _FileListToArrayRec($b,"*",2,1,0,1) $tota = UBound($fold_A)-1 $totb = UBound($fold_B)-1 If $tota > $totb Then findx($fold_A,$fold_B) Else findx($fold_B,$fold_A) EndIf Func findx($min,$max) For $i = 0 To UBound($min)-1 $found = _ArraySearch($max, $min[$i]) If $found = -1 Then ConsoleWrite($min[$i]&@CRLF) EndIf Next EndFunc  
    • Jibberish
      By Jibberish
      I am trying to add data to an array and I keep getting the error "Subscript used on non-accessible variable ".
      #include <array.au3> ; Includes, etc ~ ~ ~ Local $aOptionsArray[3] $aOptionsArray = CheckboxesAndRadioButtons() _ArrayDisplay($aOptionsArray) Func CheckboxesAndRadioButtons() ; Create Checkboxes and Radio Buttons and read the results ~ ~ ~ ; Radio Buttons to Array ; $aOptions[0] = $bTestSelectForever ; $aOptions[1] = $bTestSelect3Times ; $aOptions[2] = $bTestSelectOnce If $bSelect1 = 1 Then $aOptions[0] = "True" Else $aOptions[0] = "False" <<< This is where the error occurs. EndIf If $bSelect2 = 1 Then $aOptions[1] = "True" Else $aOptions[1] = "False" EndIf If $bSelect3 = 1 Then $aOptions[2] = "True" Else $aOptions[2] = "False" EndIf Return $aOptions EndFunc Is putting data into an array while in a If - Then - Else illegal?
    • rte7
      By rte7
      Hello. We work with the BMC Remedy site to manage incidents and would like to automate the processes of clicking through this button code:
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a> I use firefox with mozrepl and autoit with include FF.au3
      I need your help
      I read the topic https://www.autoitscript.com/forum/topic/95595-ffau3-v0601b-10/ but I could not run the code from the listed commands
      ...
      It is necessary to press the button and from the list of the menu of cahorsations to select the item = "zone of trust abonent"
      Screen # 1 http://joxi.ru/52aJK7bh4a7ypA or below.
      1) Press button
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a>
      2) After pressing the button, I need to choose in this menu of 4 items to select an item called "zone of trust abonent", Screen # 2 - http://joxi.ru/p27gwQKHo71VQ2
      html code table items
      <table class="MenuTable" cellpadding="0" cellspacing="0" style="width: 179px;"> <tbody class="MenuTableBody"> <tr class="MenuTableRow"> <td class="MenuEntryName" nowrap="">zone of trust abonent</td> <td class="MenuEntryNoSub" arvalue="zone of trust abonent"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust operator"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust third operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust third operator"></td></tr> <tr class="MenuTableRow"><td class="MenuEntryNameHover" nowrap="">No settings</td> <td class="MenuEntryNoSubHover" arvalue="No settings"></td> </tr> </tbody> </table>
       
       
      More in detail, I choose from the menu item "zone of trust abonent" Screen # 3 - http://joxi.ru/GrqVq4ZIQEPW4m

       
      3) The choice is made, Screen # 4 http://joxi.ru/v297w6aC3PovLr
      <textarea class="text sr " wrap="off" id="arid_WIN_0_1000002488" cols="20" maxlen="60" style="top:21; left:0; width:179; height:21;" armenu="CFG:PRC:CategoryHPD-Res-T1-Q" mstyle="2" arautoc="1" arautocmb="1" arautocak="0" arautoctt="400" rows="1"> </textarea>
       
      It's all. I would be very grateful to you =) !!!!!!!!!!
      Here are more detailed codes in the attachment. 
      button1.txt
      menu - table.txt
      all.txt
    • anoig
      By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig
       
    • milos83
      By milos83
      How can I check if element is focused in Firefox using FF.au3 UDF?
      This is my try:
      I have prepared a function that checks if the object is focused:
       
      _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully.
      After a lot of try/fails I inserted an alert box in order to display the object being compared.
      Here is what I got
       
      The focused object is: [object XULElement]
      The object that I send for comparing is [object HTMLInputElement]
      Why is that?