HtmlUnit get div element by class inside DomElement?

Hello I am using the HtmlUnit library and I need to get some href attribute from a tag a

, inside some div:

<div class="threadpostedin td alt">
    <p>Forum:<br>
    <a href="programming/website-development/"
    title="Website Development">Website
    Development</a></p>
</div>

      

This div is inside <li>

which is inside<ol>

to get ol

I did this:

HtmlOrderedList l = (HtmlOrderedList) this.page.getElementById("searchbits");

      

html:

<ol class="searchbits" id="searchbits" start="1">

      

Now from the div that I have placed I need to get the href "programming/website-development/"

, but I'm not sure how. Yes the div has a class name, but if I do

for (DomElement ele : l.getChildElements()) {
    System.out.println(ele.getByXPath("//div[@class='threadpostedin td alt']").size());
    break;
}

      

it will print 15 because ol

there are 15 lists in total , each list has one div with a class threadpostedin td alt

. What I need to do is the exact div with a class threadpostedin td alt

in DomElement

that I got from iterating over and not get a list of all divs with that class.

Is there a way to do this using HtmlUnit?

+3


source to share





All Articles