StartingGroovy
StartingGroovy

Reputation: 2860

Groovy htmlunit getByXPath

I'm currently using HtmlUnit to attempt to grab an href out of a page and am having some trouble.

The XPath is:

/html/body/div[2]/div/div/table/tbody/tr/td[2]/div/div[5]/div/div[2]/span/a    

On the webpage it looks like:

<a class="t" title="This Brush" href=http://domain.com/this/that">Brush Set</a>

In my code I am doing:

hrefs = page.getByXPath("//html/body/div[2]/div/div/table/tbody/tr/td[2]/div/div[5]/div/div[2]/span/a[@class='t']")

However, this is returning everything in there instead of just the url that I want.

Can someone explain what I must add to get the href? (also it doesn't end with .html)

Upvotes: 1

Views: 1039

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66724

You are selecting the a. You want to select the a/@href.

hrefs = page.getByXPath("//html/body/div[2]/div/div/table/tbody/tr/td[2]/div/div[5]/div/div[2]/span/a[@class='t']/@href")

Upvotes: 5

Related Questions