How to get the exact text of href attribute of tag a?
I think you cannot get that "href". Selenium only provides a full path or a relative path. See code below:
String href = linx.getAttribute("href");System.out.println("Text is" + href);String pathName = linx.getAttribute("pathname");System.out.println("Text is" + pathName);// Results// Text is http://www.amazon.com/gp/yourstore/home/ref=nav_cs_ys/180-1519742-0316250// Text is /gp/yourstore/home/ref=nav_cs_ys/180-1519742-0316250
You can obtain href
attribute by reading the whole element:
lLinks.getAttribute("outerHTML")
Which gives you e.g.:
<a id="button-id" href="#">Click me!</a>
Then you can use pattern matching to get the href
attribute.