Dmp Posted August 4, 2021 Share Posted August 4, 2021 Hello, I am new to this forum and to Autoit, therefore, if you would please pardon my ignorance. I have multiple items, or nodes, in a webpage that I am trying to click on, one right after another, and I am hoping that I can loop through an "array For statement" in order to use the array's element variable as a substitute where the xpath syntax is unique to each item. Unfortunately, what I have tried has not worked; see code below. This is the xpath that I've been given from SelectorsHub: (... "//div[@class='leaflet-marker-pane']//div[1]"). Each item has a different numerical value at the very of the //div expression: //div[1]") , or //div[2]"), //div[17]"), etc. Is there a way to use a variable within the xpath syntax? Local $iMax Local $sData = "1,2,3,4,5,6,7,8,9,10,11,12,1,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,30,31,32,33" Local $aDiv = StringSplit($sData, ",") If IsArray($aDiv) Then _ArrayDisplay($aDiv) $iMax = UBound($aDiv) For $i = 0 to $iMax -1 Local $iElmnt = $aDiv[$i] ; MsgBox($MB_SYSTEMMODAL, "Var", "Var is: " & $iElmnt, 5) $sFElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='leaflet-marker-pane']//div[$iElmnt]") _WD_ElementAction($sSession, $sFElement, 'click') Sleep(2000) Next EndIf Link to comment Share on other sites More sharing options...
Danp2 Posted August 4, 2021 Share Posted August 4, 2021 Hi! You are passing a string to _WD_FindElement, so you'll need to concatenate the variable into the string -- $sFElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='leaflet-marker-pane']//div[" & $iElmnt & "]") P.S. See here for the proper method of posting code on the forum Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Dmp Posted August 4, 2021 Author Share Posted August 4, 2021 Thank you so much for your response and in showing me what I needed to do to make it work! I have been reading these forums for a while now and am very impressed w/ the content and the considerable support given to the participants. Danp2 1 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