SatheshVp Posted May 27, 2024 Posted May 27, 2024 (edited) I'm getting the Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded site for the below code. I have integrated AutoIt with Selenium. While compiling the script I'm not getting any error but while running the script I'm getting this error. Please help. AutoIt code: expandcollapse popup#include <ScreenCapture.au3> $option = $CmdLine[4] $filepath = $CmdLine[1] $sspath =$CmdLine[2] $sspath2 = $CmdLine[3] ControlFocus("Select Folder to Upload","","Edit1") if $option = "screenshot" Then popupIsDisplayed() ElseIf $option = "cancel" Then clickCancelInPopUp() ElseIf $option = "select file" Then selectFile() clickUploadInPopUp() ElseIf $option = "alert screenshot" Then alertISDisplayed() ElseIf $option = "upload" Then clickUploadInAlert() ElseIf $option = "cancel alert" Then clickCancelInAlert() EndIf Exit Func popupIsDisplayed() ControlFocus("Select Folder to Upload","","Edit1") Sleep(2000) Example() EndFunc Func clickCancelInPopUp() ControlClick("Select Folder to Upload","","Button2") EndFunc Func selectFile() ControlSetText("Select Folder to Upload","","Edit1", $filepath) Sleep(2000) Example() Sleep(2000) EndFunc Func clickUploadInPopUp() ControlClick("Select Folder to Upload","","Button1") Sleep(2000) EndFunc Func alertISDisplayed() Example2() EndFunc Func clickUploadInAlert() Example2() Send("{Tab}") Send("{Enter}") EndFunc Func clickCancelInAlert() Example2() Send("{Enter}") EndFunc Func Example() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath, $hBmp) EndFunc ;==>Example Func Example2() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath2, $hBmp) EndFunc ;==>Example Java Code: String autoItScriptPath = System.getProperty("user.dir") + "\\src\\test\\resources\\autoit\\FileUpload.exe"; public void uploadFile(String folderName) throws IOException, InterruptedException { String folderPath = System.getProperty("user.dir") + "\\src\\test\\resources\\datasets\\"+folderName; String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1", LoginPage.driver); String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" }; Runtime.getRuntime().exec(cmd); Thread.sleep(5000); } public void alertIsDisplayed() throws IOException, InterruptedException { String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1", LoginPage.driver); String[] cmd = { autoItScriptPath, "", SSPath, "", "alert screenshot" }; Runtime.getRuntime().exec(cmd); Thread.sleep(3000); } public static String uploadTime = null; public void clickUploadInAlert() throws IOException, InterruptedException { String SSPath2 = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "2", LoginPage.driver); String[] cmd = { autoItScriptPath, "", "", SSPath2, "upload" }; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a"); LocalDateTime now = LocalDateTime.now(); Runtime.getRuntime().exec(cmd); Thread.sleep(3000); uploadTime = dtf.format(now); logger.info("uploadTime: " +uploadTime); } Edited May 27, 2024 by Jos added codeboxes
paw Posted May 27, 2024 Posted May 27, 2024 Check that $CmdLine actually contains the stuff you pass to AutoIt using _ArrayDisplay($CmdLine) You are somehow accessing an array element that doesn't exist. Use Ubound($CmdLine) to check the size of the array and handle error cases. SatheshVp 1
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 @pawI'm not getting you, where should I update the code.
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 Just now, SatheshVp said: @pawI'm not getting you, where should I update the code. 20 minutes ago, SatheshVp said: I'm getting the Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded site for the below code. I have integrated AutoIt with Selenium. While compiling the script I'm not getting any error but while running the script I'm getting this error. Please help. AutoIt code: #include <ScreenCapture.au3> $option = $CmdLine[4] $filepath = $CmdLine[1] $sspath =$CmdLine[2] $sspath2 = $CmdLine[3] ControlFocus("Select Folder to Upload","","Edit1") if $option = "screenshot" Then popupIsDisplayed() ElseIf $option = "cancel" Then clickCancelInPopUp() ElseIf $option = "select file" Then selectFile() clickUploadInPopUp() ElseIf $option = "alert screenshot" Then alertISDisplayed() ElseIf $option = "upload" Then clickUploadInAlert() ElseIf $option = "cancel alert" Then clickCancelInAlert() EndIf Exit Func popupIsDisplayed() ControlFocus("Select Folder to Upload","","Edit1") Sleep(2000) Example() EndFunc Func clickCancelInPopUp() ControlClick("Select Folder to Upload","","Button2") EndFunc Func selectFile() ControlSetText("Select Folder to Upload","","Edit1", $filepath) Sleep(2000) Example() Sleep(2000) EndFunc Func clickUploadInPopUp() ControlClick("Select Folder to Upload","","Button1") Sleep(2000) EndFunc Func alertISDisplayed() Example2() EndFunc Func clickUploadInAlert() Example2() Send("{Tab}") Send("{Enter}") EndFunc Func clickCancelInAlert() Example2() Send("{Enter}") EndFunc Func Example() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath, $hBmp) EndFunc ;==>Example Func Example2() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath2, $hBmp) EndFunc ;==>Example Java Code: String autoItScriptPath = System.getProperty("user.dir") + "\\src\\test\\resources\\autoit\\FileUpload.exe"; public void uploadFile(String folderName) throws IOException, InterruptedException { String folderPath = System.getProperty("user.dir") + "\\src\\test\\resources\\datasets\\"+folderName; String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1", LoginPage.driver); String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" }; Runtime.getRuntime().exec(cmd); Thread.sleep(5000); } public void alertIsDisplayed() throws IOException, InterruptedException { String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1", LoginPage.driver); String[] cmd = { autoItScriptPath, "", SSPath, "", "alert screenshot" }; Runtime.getRuntime().exec(cmd); Thread.sleep(3000); } public static String uploadTime = null; public void clickUploadInAlert() throws IOException, InterruptedException { String SSPath2 = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "2", LoginPage.driver); String[] cmd = { autoItScriptPath, "", "", SSPath2, "upload" }; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a"); LocalDateTime now = LocalDateTime.now(); Runtime.getRuntime().exec(cmd); Thread.sleep(3000); uploadTime = dtf.format(now); logger.info("uploadTime: " +uploadTime); } @Jos
Developers Jos Posted May 27, 2024 Developers Posted May 27, 2024 (edited) @SatheshVp What about you slow down a bit and stop begging/pinging people for support? This is considered very impolite and puts people off! Who made this code for you, as you seems to be lost? Edited May 27, 2024 by Jos SatheshVp 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 @Jos Apologies for the discomfort. I didn't write this AutoIt code. It was written by some other person who is currently not in my company now. I'm new to the company and I don't see any person who has AutoIt knowledge in my project. Could you please help resolving this bug if you get time?
Developers Jos Posted May 27, 2024 Developers Posted May 27, 2024 Guess you have some studying to do then! You didn't specify, but the guess is you get the error on one of these: $option = $CmdLine[4] $filepath = $CmdLine[1] $sspath =$CmdLine[2] $sspath2 = $CmdLine[3] Which is because you started the script without (enough) parameters and the coder has forgotten to test for that! So open the AutoIt3 helpfile and look at the Running Scripts topic. SatheshVp 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 @JosI have gone through the Running Scripts topic. I'm still having confusion. I'm passing the array values in this array String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" }; to AutoIt $CmdLine[1] is folder path $CmdLine[2] is SSPath $CmdLine[3] is null $CmdLine[4] is "select file" $CmdLine[0] is "\\src\\test\\resources\\autoit\\FileUpload.exe" [AutoIt .exe path] But $CmdLine[0] means total number of items in the array in AutoIt. How to tackle this one?
Developers Jos Posted May 27, 2024 Developers Posted May 27, 2024 Add these 3 lines at the top of your script: #include <Array.au3> _ArrayDisplay($CmdLine) Exit ..compile it and run it again. It should show the full $CmdLine array in a popup so you can see what is happening. SatheshVp 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 @JosThanks, I found where the issue is. Array in AutoIt is not considering null value(""). Actual: $CmdLine[0] = number of items $CmdLine[1] = folder path $CmdLine[2] = SSPath $CmdLine[3] ="select file" Expected: $CmdLine[0] = number of items $CmdLine[1] = folder path $CmdLine[2] = SSPath $CmdLine[3] = "" $CmdLine[4] ="select file" How can we pass null value ("")?
Nine Posted May 27, 2024 Posted May 27, 2024 (edited) Just pass a dummy parameter, like "NULL" or specific character like "*". Anything beside nothing.... ps. In java you need to escape quotation marks if you want to send them, this would be a valid parameter : "\"\"" and it would be interpreted as Null value in AutoIt (like suggested by @argumentum below) Edited May 27, 2024 by Nine SatheshVp 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
argumentum Posted May 27, 2024 Posted May 27, 2024 (edited) 2 hours ago, SatheshVp said: How can we pass null value ("")? just do it. For $n = 1 To $CmdLine[0] ConsoleWrite($n & @TAB & '>' & $CmdLine[$n] & '<' & @CRLF) Next Exit I passed 1 "" 3 4 and got 1 >1< 2 >< 3 >3< 4 >4< so yes you can. What I would do in your case is Global $option, $filepath, $sspath, $sspath2 If $CmdLine[0] > 3 Then $option = $CmdLine[4] If $CmdLine[0] > 0 Then $filepath = $CmdLine[1] If $CmdLine[0] > 1 Then $sspath =$CmdLine[2] If $CmdLine[0] > 2 Then $sspath2 = $CmdLine[3] so you don't get the error you got with your code. Then again, you'll have to learn to think and explore on your own. My 2 cents even if you don't like it Edited May 27, 2024 by argumentum SatheshVp 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution ioa747 Posted May 27, 2024 Solution Posted May 27, 2024 my approach expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <ScreenCapture.au3> Global $aArgs = $CmdLine ;~ Global $aArgs = [5, "one", 2, "three", "", "five"] ;test Global $filepath, $sspath, $sspath2, $option If $aArgs[0] = 4 Then $aArgs[0] = "CallArgArray" Call("_main", $aArgs) Else Global $sMsg = "Number of parameters: " & $aArgs[0] & @CRLF For $i = 1 To $aArgs[0] $sMsg &= $i & ") " & $aArgs[$i] & @CRLF Next ToolTip($sMsg , Default, Default, "!! Wrong Number of parameters", 3) Sleep(4000) EndIf Exit Func _main($sArg1, $sArg2, $sArg3, $sArg4) $filepath = $sArg1 $sspath = $sArg2 $sspath2 = $sArg3 $option = $sArg4 ControlFocus("Select Folder to Upload", "", "Edit1") If $option = "screenshot" Then popupIsDisplayed() ElseIf $option = "cancel" Then clickCancelInPopUp() ElseIf $option = "select file" Then selectFile() clickUploadInPopUp() ElseIf $option = "alert screenshot" Then alertISDisplayed() ElseIf $option = "upload" Then clickUploadInAlert() ElseIf $option = "cancel alert" Then clickCancelInAlert() EndIf EndFunc ;==>_main Func popupIsDisplayed() ControlFocus("Select Folder to Upload", "", "Edit1") Sleep(2000) Example() EndFunc ;==>popupIsDisplayed Func clickCancelInPopUp() ControlClick("Select Folder to Upload", "", "Button2") EndFunc ;==>clickCancelInPopUp Func selectFile() ControlSetText("Select Folder to Upload", "", "Edit1", $filepath) Sleep(2000) Example() Sleep(2000) EndFunc ;==>selectFile Func clickUploadInPopUp() ControlClick("Select Folder to Upload", "", "Button1") Sleep(2000) EndFunc ;==>clickUploadInPopUp Func alertISDisplayed() Example2() EndFunc ;==>alertISDisplayed Func clickUploadInAlert() Example2() Send("{Tab}") Send("{Enter}") EndFunc ;==>clickUploadInAlert Func clickCancelInAlert() Example2() Send("{Enter}") EndFunc ;==>clickCancelInAlert Func Example() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath, $hBmp) EndFunc ;==>Example Func Example2() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath2, $hBmp) EndFunc ;==>Example2 SatheshVp 1 I know that I know nothing
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 3 hours ago, Nine said: Just pass a dummy parameter, like "NULL" or specific character like "*". Anything beside nothing.... ps. In java you need to escape quotation marks if you want to send them, this would be a valid parameter : "\"\"" and it would be interpreted as Null value in AutoIt (like suggested by @argumentum below) Thank you!!!
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 4 minutes ago, ioa747 said: my approach expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <ScreenCapture.au3> Global $aArgs = $CmdLine ;~ Global $aArgs = [5, "one", 2, "three", "", "five"] ;test Global $filepath, $sspath, $sspath2, $option If $aArgs[0] = 4 Then $aArgs[0] = "CallArgArray" Call("_main", $aArgs) Else Global $sMsg = "Number of parameters: " & $aArgs[0] & @CRLF For $i = 1 To $aArgs[0] $sMsg &= $i & ") " & $aArgs[$i] & @CRLF Next ToolTip($sMsg , Default, Default, "!! Wrong Number of parameters", 3) Sleep(4000) EndIf Exit Func _main($sArg1, $sArg2, $sArg3, $sArg4) $filepath = $sArg1 $sspath = $sArg2 $sspath2 = $sArg3 $option = $sArg4 ControlFocus("Select Folder to Upload", "", "Edit1") If $option = "screenshot" Then popupIsDisplayed() ElseIf $option = "cancel" Then clickCancelInPopUp() ElseIf $option = "select file" Then selectFile() clickUploadInPopUp() ElseIf $option = "alert screenshot" Then alertISDisplayed() ElseIf $option = "upload" Then clickUploadInAlert() ElseIf $option = "cancel alert" Then clickCancelInAlert() EndIf EndFunc ;==>_main Func popupIsDisplayed() ControlFocus("Select Folder to Upload", "", "Edit1") Sleep(2000) Example() EndFunc ;==>popupIsDisplayed Func clickCancelInPopUp() ControlClick("Select Folder to Upload", "", "Button2") EndFunc ;==>clickCancelInPopUp Func selectFile() ControlSetText("Select Folder to Upload", "", "Edit1", $filepath) Sleep(2000) Example() Sleep(2000) EndFunc ;==>selectFile Func clickUploadInPopUp() ControlClick("Select Folder to Upload", "", "Button1") Sleep(2000) EndFunc ;==>clickUploadInPopUp Func alertISDisplayed() Example2() EndFunc ;==>alertISDisplayed Func clickUploadInAlert() Example2() Send("{Tab}") Send("{Enter}") EndFunc ;==>clickUploadInAlert Func clickCancelInAlert() Example2() Send("{Enter}") EndFunc ;==>clickCancelInAlert Func Example() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath, $hBmp) EndFunc ;==>Example Func Example2() Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($sspath2, $hBmp) EndFunc ;==>Example2 Thank you!!! ioa747 1
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 3 hours ago, argumentum said: just do it. For $n = 1 To $CmdLine[0] ConsoleWrite($n & @TAB & '>' & $CmdLine[$n] & '<' & @CRLF) Next Exit I passed 1 "" 3 4 and got 1 >1< 2 >< 3 >3< 4 >4< so yes you can. What I would do in your case is Global $option, $filepath, $sspath, $sspath2 If $CmdLine[0] > 3 Then $option = $CmdLine[4] If $CmdLine[0] > 0 Then $filepath = $CmdLine[1] If $CmdLine[0] > 1 Then $sspath =$CmdLine[2] If $CmdLine[0] > 2 Then $sspath2 = $CmdLine[3] so you don't get the error you got with your code. Then again, you'll have to learn to think and explore on your own. My 2 cents even if you don't like it Thank you!!!
SatheshVp Posted May 27, 2024 Author Posted May 27, 2024 3 hours ago, SatheshVp said: @JosThanks, I found where the issue is. Array in AutoIt is not considering null value(""). Actual: $CmdLine[0] = number of items $CmdLine[1] = folder path $CmdLine[2] = SSPath $CmdLine[3] ="select file" Expected: $CmdLine[0] = number of items $CmdLine[1] = folder path $CmdLine[2] = SSPath $CmdLine[3] = "" $CmdLine[4] ="select file" How can we pass null value ("")? Thank you!!!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now