SkysLastChance Posted August 5, 2021 Share Posted August 5, 2021 I have seen some similar post, but not sure how to implement using Web-driver. So my problem is I am looking for all instances of the word "yes" on my webpage. (chrome) The problem is "yes" may be there once or even not at all. I understand why I am getting the error. Because it is not always a array. However, the error is causing my script to end. I don't want it to end the query. I just want it to continue on. Here is an example: This will click the first and second instance of "yes' on the webpage. (as long as it exists) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'Yes')]","",True) _WD_ElementAction($sSession, $sElement[0], 'click') Sleep (2000) _WD_ElementAction($sSession, $sElement[1], 'click') This is the error I am getting. "C:\Users\******\Desktop\Expanse Auto Reg Test.au3" (44) : ==> Subscript used on non-accessible variable.: _WD_ElementAction($sSession, $sElement[0], 'click') _WD_ElementAction($sSession, $sElement^ ERROR ->14:41:54 AutoIt3.exe ended.rc:1 +>14:41:54 AutoIt3Wrapper Finished. >Exit code: 1 Time: 21.74 You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Solution seadoggie01 Posted August 5, 2021 Solution Share Posted August 5, 2021 (edited) ; Note that we usually say 'a' before array type variables Local $aElement = _WD_FindElement(...) ; For each element in the array For $i=0 To UBound($aElement) - 1 ; Perform the action on that element, we access it with $i, which goes from 0, 1, 2, etc until the size of the array _WD_ElementAction($sSession, $aElement[$i], "click") Next Edit: You should probably be checking for @error after each _WD_ call if you aren't already Edited August 5, 2021 by seadoggie01 SkysLastChance 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted August 5, 2021 Share Posted August 5, 2021 IsArray($array) will tell you if there is an array returned by the function and Ubound will tell you the number of occurrences found SkysLastChance and seadoggie01 2 “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...
SkysLastChance Posted August 5, 2021 Author Share Posted August 5, 2021 (edited) I had to add some delay. probably a little overkill but it works. Thank you both! Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'Yes')]","",True) ; For each element in the array For $i=0 To UBound($aElement) - 1 ; Perform the action on that element, we access it with $i, which goes from 0, 1, 2, etc until the size of the array _WD_ElementAction($sSession, $aElement[$i], "click") If @error <> $_WD_ERROR_Success Then MsgBox(0, "Error","Could not click 'Yes' Button " & $i) Sleep (2000) Next Edited August 6, 2021 by SkysLastChance You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott 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