Reputation: 2337
I have a link on the webpage. I want to right click and copy the link location is it possible through selenium 1? For example I have a webpage opened and it has a link "add book" and it manually if i right click and do copy link location then it points to http://webserver/webapps/books/addbook.jsp?book_id=44_1&type=reference&promo=none
Is there a way to find out to copy the link by giving an XPath of the text :"add book" ? Or using javascript?
Thanks in advance.
Upvotes: 7
Views: 19648
Reputation: 4536
Am using bellow code to get link location (With Selenium-WebDriver and java binding) :
WebElement link = driver.findElement(By.linkText("add book"));
String linkLocatin = link.getAttribute("href");
System.out.println("Link Location "+linkLocatin);
Upvotes: 7
Reputation: 344
In Selenese I use something like this:
<tr>
<td>storeAttribute</td>
<td>xpath=//a[text()="add book"]@href</td>
<td>linkToBook</td>
</tr>
<tr>
<td>echo</td>
<td>${linkToBook}</td>
<td></td>
</tr>
Upvotes: 1
Reputation: 2194
The Selenium-interface has a
getHtmlSource()
-method. This returns a String, on which you can apply an Xpath like this:
//a[text()="add book"]
Upvotes: 0