Reputation: 2633
this is a link on a page im automating:
and this is when I inspect it's element:
I want to get only the
/console/agent_invoices/2297294
which is the href...
How can I do this?
thanks!
Upvotes: 1
Views: 3584
Reputation: 513
First find element and get its attribute value in variable as explained below.
String linkText = webDriver.findElement(By.tagName("a")).getAttribute("href");
Upvotes: 2
Reputation: 6909
You can use the getAttribute
method:
String hrefText = yourLinkElement.getAttribute("href");
If you also need to find your linkElement first, you need to provide more code.
Given you only have one link Element:
WebElement yourLinkElement = driver.findElement(By.tagName("a));
Or for example if you already identified the div-Element, that we see with the closing tag in your question you can do this:
WebElement yourLinkElement = divElement.findElement(By.tagName("a));
Upvotes: 3