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.
Using Link Text In Selenium To Locate An Element In order to access link using link text in Selenium, the below-referenced code is used: driver. findElement(By. linkText("this is a link text"));
We can click a link by href value with Selenium webdriver. To identify the link with the href attribute we can take the help of the locators xpath or css selector. We shall use the findElement method and pass By.
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);
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With