Search code examples
javahtmlunit

Getting href from parent anchor HtmlUnit


What I am trying to do is to use HtmlUnit to get the href from the parent anchor of a span. Here is what I mean.

  <a href="http://link.com/serv?id=jibberish&type=dynamic/changeseachvisit"><span>Some Unique Text</span></a>

There is no id or name associated with either the or the tags, so going by this example, how would you find that link in a sea of others like it without ids or names? Thanks!


Solution

  • use the XPATH //span[contains(.,'Transcript')]/parent::a/@href

    (non tested, but XPATH is definitely the way to go)