Jump to content

Get HTML from DIV class name and loop


Recommended Posts

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 by cbielich
Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...