cbielich Posted August 15, 2022 Share Posted August 15, 2022 (edited) I am working with the web driver, back in the day when we had IE I had no issues with this but now...lol For the life of me I can't find out how to get the HTML within a DIV from its class name. I am using XPath to get the div by class. From my understand I need to use _WD_ElementAction to retrieve the "html", but the only thing I use that returns anything is "text" which obviously I can't use. I need the HTML so I can loop through them to parse out what I need. What am I doing wrong? <div class="coverage-info"> <div class="row"> <div class"class1">Some Title:</div> <div class="class2">Some value I need</div> </div> <div class="row"> <div class"class1">Some Title:</div> <div class="class2">Some value I need</div> </div> <div class="row"> <div class"class1">Some Title:</div> <div class="class2">Some value I need</div> </div> </div> Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[contains(@class,'coverage-info')]") Local $sValue = _WD_ElementAction($sSession, $sElement, 'text') Then I would loop through the elements with something like For $value In $sValue $class_value = $value.GetAttribute("class") If $class_value = "class1" Then MsgBox(0, "Found", $value.innertext) EndIf Next Edited August 15, 2022 by cbielich Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2022 Share Posted August 15, 2022 Have you tried something like this? -- $sHTML = _WD_ElementAction($sSession, $sElement, 'property', 'innerHTML') Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
cbielich Posted August 15, 2022 Author Share Posted August 15, 2022 You are a god send! is there somewhere that better describes the "property" sCommand and what values are available? Link to comment Share on other sites More sharing options...
cbielich Posted August 15, 2022 Author Share Posted August 15, 2022 I also have noticed that _WD_ElementAction does not return as on object which I need for a For loop, is there a way to convert it to an object so I can loop through the elements? Link to comment Share on other sites More sharing options...
cbielich Posted August 15, 2022 Author Share Posted August 15, 2022 I got it! Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[contains(@class,'coverage-info')]") Local $sHTML = _WD_ElementAction($sSession, $sElement, 'property', 'innerHTML') $str = stringregexpreplace($sHTML,'\[b\]','') $str = stringregexpreplace($str,'\[/b\]','') $ret = stringregexp($str,'>(.*?)<',3) for $1 = ubound($ret) - 1 to 0 step -1 if stringlen(stringstripws($ret[$1],3)) = 0 then _arraydelete($ret,$1) next _arraydisplay($ret) Thanks to kylomas Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2022 Share Posted August 15, 2022 17 minutes ago, cbielich said: is there somewhere that better describes the "property" sCommand and what values are available? You can use "property" or "attribute" to access any available property / attribute for a given element. These are defined by HTML and the DOM. Use your favorite search engine to get more into. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
cbielich Posted August 15, 2022 Author Share Posted August 15, 2022 ohhh got it, thanks! 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