goku200 Posted July 12, 2021 Share Posted July 12, 2021 (edited) I have a script that I have created that's supposed to upload images using _WD_SelectFiles. The looping of my script works as expexted, however it uploads the same image for each image 4 times. It then loops to the next image, but it continues to upload it 4 times of the same name image. Below is my script. Any help is greatly appreciated 🙂 expandcollapse popup#Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "http://127.0.0.1/upload.html") _WD_LoadWait($sSession) Local $aList = _FileListToArrayRec("C:\Test\images\", "*|*.db", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT) _ArrayDisplay($aList) For $i = UBound($aList) - 1 To 0 Step - 1 _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file1']", @ScriptDir & "\images\" & $aList[$i]) _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file2']", @ScriptDir & "\images\" & $aList[$i]) _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file3']", @ScriptDir & "\images\" & $aList[$i]) _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file4']", @ScriptDir & "\images\" & $aList[$i]) Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc Edited July 12, 2021 by goku200 Link to comment Share on other sites More sharing options...
Danp2 Posted July 12, 2021 Share Posted July 12, 2021 You are assigning the same value ($aList[$i]) to each of the input elements. Therefore, the same image gets uploaded four times just like you told it to do. 😄 Your loop code will need to be rewritten so that it -- assigns different values to each element uses a different step value makes sure it doesn't exceed array size (ie: if you start using $i+1, $i+2, etc) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
goku200 Posted July 12, 2021 Author Share Posted July 12, 2021 (edited) @Danp2Thanks for the reply. Are you saying change: _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file1']", @ScriptDir & "\images\" & $aList[$i]) To: _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file1']", @ScriptDir & "\images\" & $i + 1) A little confused as to what I need to change 🙂 Edited July 12, 2021 by goku200 Link to comment Share on other sites More sharing options...
Danp2 Posted July 12, 2021 Share Posted July 12, 2021 Untested, but I was suggesting that you change your code to something like this -- $iMax = UBound($aList) - 1 For $i = 0 To $iMax Step 4 For $j = 0 To 3 $iIndex = $i + $j If $iIndex > $iMax Then ExitLoop 2 _WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='file" & $j + 1 & "']", @ScriptDir & "\images\" & $aList[$iIndex]) Next Next Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
goku200 Posted July 12, 2021 Author Share Posted July 12, 2021 Thank you @Danp2. Quick question is there a reason why it doesn't select the the first upload input? It goes straight to the second input, third input, fourth input..... and then when it re-loops it selects the first input for the remaining image in that folder to be uploaded Output says File Not Found: C:\\Test\\images\\ Link to comment Share on other sites More sharing options...
Danp2 Posted July 12, 2021 Share Posted July 12, 2021 (edited) You could try adding some calls to ConsoleWrite throughout the code to help you troubleshoot it. You could also modify the line with _FileListToArrayRec to use $FLTAR_FULLPATH for the return path. Then you can eliminate the following portion of code and just use the raw contents of the array -- @ScriptDir & "\images\" Edit: I took a closer look at the array created by _FileListToArrayRec, and the first entry contains the number of returned entries. Therefore, you need to change the line $iIndex = $i + $j to $iIndex = $i + $j + 1 so that you start processing the array at position 1 instead of 0. Edited July 12, 2021 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
goku200 Posted July 12, 2021 Author Share Posted July 12, 2021 @Danp2 I actually added that 1 on my end before replying back 😁. Always enjoy learning from you and the rest of the community on here. Link to comment Share on other sites More sharing options...
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