goku200 Posted February 19, 2021 Share Posted February 19, 2021 (edited) I'm having some issues with writing to column C when an element is found. It works on C2 but it does not continue to C3, C4, C5, etc..... I'm wanting to write "test" if the element //input[@id='username'] is found $someUser = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']"). I have attached my HTML and Excel file along with my AutoIt code below: expandcollapse popup#Include "wd_core.au3" #Include "wd_helper.au3" #Include "wd_core.au3" #Include "File.au3" #Include "Array.au3" #Include "Excel.au3" Local $sDesiredCapabilities, $sSession _WD_Startup() $Ssession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://127.0.0.1/test.html") _WD_LoadWait($sSession) Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\<Username>\Downloads\test.xlsx") Local $aArrayTest1 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $aArrayTest2 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) For $i = 0 To UBound($aArrayTest1) - 1 _WD_Navigate($Ssession, $aArrayTest1[$i]) _WD_LoadWait($sSession) $someUser = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']") _WD_SetElementValue($sSession, $someUser, $aArrayTest2[$i]) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@type='submit'][@value='Submit']") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession) Sleep(5000) If $someUser Then Local $aArray2D[2] = ["test"] _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $aArray2D, "C2") EndIf Next 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 ;==>SetupChrome test.html test.xlsx Edited February 20, 2021 by goku200 Link to comment Share on other sites More sharing options...
Bert Posted February 20, 2021 Share Posted February 20, 2021 Before writing to the excel file, try using _arrayDisplay to see if your array is getting you what you expect. https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDisplay.htm The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
goku200 Posted February 20, 2021 Author Share Posted February 20, 2021 (edited) Thank you for the reply Bert. I modified my code to read the range and used the _ArrayDisplay to display my columns. It displays all 3 columns but still only writes to C2. Not sure why it's not continuing to the next cell (C3, C4,etc... Edited February 24, 2021 by goku200 Link to comment Share on other sites More sharing options...
Nine Posted February 20, 2021 Share Posted February 20, 2021 Because you are writing a single string "test" to a single location. It is done a number of times [ubound(...)-1] but it still writes to the same cell. You need to modify the range or send an array instead of a single data. “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
goku200 Posted February 20, 2021 Author Share Posted February 20, 2021 (edited) When I change it to send an array it does not write to the cell using that array Edited February 24, 2021 by goku200 Link to comment Share on other sites More sharing options...
Nine Posted February 20, 2021 Share Posted February 20, 2021 You did not understand what I was trying to explain. First way (changing range) : Local $aArrayTest3 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("A:C")) For $i = 0 To UBound($aArrayTest3) - 1 _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $i, "C" & $i+2) Next Second way (passing an array) : Local $aArrayTest3 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("A:C")) _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $aArrayTest3, "C2") “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Developers Jos Posted February 20, 2021 Developers Share Posted February 20, 2021 (edited) @goku200 or should I say @j1osu2002, Why have you created a new account to ask similar questions? And while I have your attention: What is the real purpose of this script? @ everybody else, please stay out for the moment. Jos Edited February 20, 2021 by Jos 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. Link to comment Share on other sites More sharing options...
goku200 Posted February 20, 2021 Author Share Posted February 20, 2021 (edited) I had accidentally created an extra account and didn't realized i was using the other account. my purpose is to loop through the first loop and go to each link in the spreadsheeet and populate a number in the input field. If the input element is found I'm trying to write "test" in Column C starting at C2 and C3, etc...I got as far as to writing to the column but its writing test only to column C2. Apologize about the extra account Edited February 24, 2021 by goku200 Link to comment Share on other sites More sharing options...
Developers Jos Posted February 20, 2021 Developers Share Posted February 20, 2021 1 hour ago, goku200 said: I had accidentally created an extra account and didn't realized i was using the other account. mmm accidently uh ... 🤔 I have merge the 2 accounts into your last one and please stick to the forum rules from here on. Thanks, Jos 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. Link to comment Share on other sites More sharing options...
goku200 Posted February 20, 2021 Author Share Posted February 20, 2021 Thank you @Jos. Also, I was able to figure out the script I ended up calling the array and was able to output what I needed. Thanks for the snippet @Nine 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