0

I'm trying to click on a "More" anchor tag on a website using HtmlUnit in order to expand a list until the more anchor tag does not exist.

page = client.getPage(url);

HtmlAnchor anchor;

while((anchor = page.getFirstByXPath("//a[@class='load-more list']")) != null) {

page = (HtmlPage) anchor.getPage();

}

I've also tried page = anchor.click();

System.out.println(anchor) shows

HtmlAnchor[ a href="/guideitem/list/?id=g407&requestType=browse&filter=ZmlsdGVyPXMlM2FmcmVlJmxpbWl0PTMw" class="load-more list" data-hijax="false" ]

I will continue to look into this problem and post what I find here.

God Usopp
  • 331
  • 1
  • 6
  • 18

1 Answers1

0

I've had a somewhat similar problem, hope this helps. It "solved itself" after we disabled CSS on the WebClient:

webClient.getOptions().setCssEnabled(false);

My anchor was:

<div class="my-anchors-parent-class"/>
  <a href="javascript:void(0) class="text" id="buttonSearch" style="display: block;">Search</a>
</div>

It had some JQuery attaching the .click() handler to it, who acted based on the 'class' property of my anchor's parent:

    $('.my-anchor's-parent-class').each(function () {
        $(this).children('a').click(function () {
          // if parent has another given class appended, call .myFunction(this)
          // else, call other function
        });
    });

When we reenable the CSS, the .click() is broken again.

vergatti
  • 166
  • 1
  • 6