Jump to content

Recommended Posts

Posted (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 by cbielich
Posted

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?

Posted

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

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
  • Recently Browsing   0 members

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