Extract a value from an array and send it to screen

2.8k Views Asked by At

I want to make a monkey test for a website (click randomly and send some values to the screen). I tried the script on a Word document but the only character sent was $. How to solve this?

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author:         Vasile

Script Function:
    Monkey.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
Run("C:\Program Files\Google\Chrome\Application\chrome.exe http://quiz.interhit.net/");deschide chrome--si site QUIZ
Sleep(200) 

$activ_x = 676
$activ_y = 569

$repetari = 0
Do
    Local $array[27]
    $array[0]="F5"
    $array[1]="F1"
    $array[3]="F12"
    $array[4]="¬"
    $array[5]="1"
    $array[6]="10"
    $array[7]="-"
    $array[8]="="
    $array[9]="+"
    $array[10]="TAB"
    $array[11]="SPACE"
    $array[12]="LWIN"; WINDOWS KWY
    $array[13]="CAPSLOCK"
    $array[14]="LALT";ALT KEY
    $array[15]="Enter"
    $array[16]="ESC"
    $array[17]="DELETE"
    $array[18]="BACKSPACE"
    $array[19]="SCROLLLOCK"
    $array[20]="LSHIFT"
    $array[21]="A"
    $array[22]="Z"
    $array[23]="a"
    $array[24]="z"
    $array[25]="1"
    $array[26]="10"
    $x = Random(10, 900, 1)
    $y = Random(10, 600, 1)
    $chr = Random(0,27,1)
    Local $i = 0
    While $i<= 3
        MouseClick("left", $y, $x)
        Send("$array[$chr]}")
        $i = $i + 1
    WEnd
$repetari= $repetari + 1
Until $repetari = 10
2

There are 2 best solutions below

1
On

It looks like you're missing a bracket in your Send call.

Try: Send("{$array[$chr]}")

However, I think it would be preferred if you surrounded the special cases with brackets instead. (almost all your characters are special cases, except the bottom few)

IE:

$array[0] = "{F5}"
$array[1] = "{F1}"
 ....
$array[21] = "A"
$array[22] = "Z"
 ....
Send("$array[$chr]")

It's been a few years since I've done anything with Auto-It, so give that a shot and let me know how it turns out.

Take a look at all the special cases here.

0
On
    Local $i = 0
While $i<= 3
    MouseClick("left", $y, $x)
    Send("{" & $array[$chr] & "}")
    $i = $i + 1
WEnd

I figured out few hours later with a little help from a friend, the problem was that in old version I miss a two & marks to delimitate the character¬$arra[$chr]¬ in send function. I tried this solution and it's working. I will try CoderSeven answer too