Reputation: 103
I want to get the FULL text of link, that is contained in a page element and retrieve is value possibly with .getText()
parameter. Problem is, that on the page there is only part of it displayed followed by "...".
.getText returns = "http://www.example.com/es_es/spa..."
what I need to get ="http://www.example.com/es_es/spain/legal-notice.html"
this is HTML
<a href="http://www.example.com/es_es/spain/legal-notice.html"
target="_blank">http://www.example.com/es_es/spa...</a>
I am able to locate the element, just not to retrieve its full text. I tried .getAttribute("href")
but it returns "null"
.
Thank you!
Upvotes: 4
Views: 150
Reputation: 193188
You wanted to use getText()
method, but getText()
will be helpfull while we want to retrieve the innerHTML
only. But if we use getAttribute()
method, we will be able to pull out any of the attributes
of the WebElement
.
Now, to retrieve the full text of href
attribute you can use the following line of code :
System.out.println(driver.findElement(By.xpath("//a[contains(@href,'example.com/es_es/spain/legal-notice')]")).getAttribute("href"));
Upvotes: 1
Reputation: 4739
Try this using xpath :
WebElement hrefText=driver.findElement(By.xpath("//a[@href='http://www.example.com/es_es/spain/legal-notice.html']"));
String text_hrefText=hrefText.getAttribute("href");
System.out.println(text_hrefText);
Upvotes: 2