admin管理员组

文章数量:1244303

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.

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.

Share Improve this question asked Nov 18, 2011 at 8:14 java_enthujava_enthu 2,3278 gold badges46 silver badges75 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

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>

The Selenium-interface has a

getHtmlSource()

-method. This returns a String, on which you can apply an Xpath like this:

//a[text()="add book"]

本文标签: javaCan I get link location through seleniumStack Overflow