I have a well formed XHTML page. I want to find the destination URL of a link when I have the text that is linked.
Example
<a href="http://stackoverflow.com">programming questions site</a> <a href="http://cnn.com">news</a>
I want an XPath expression such that if given programming questions site
it will give http://stackoverflow.com
and if I give it news
it will give http://cnn.com
.
A linkText is used to identify the hyperlinks on a web page. It can be determined with the help of an anchor tag (<a>). In order to create the hyperlinks on a web page, you can use anchor tags followed by the linkText. Now, let's examine linkText locator with the help of an example.
This will get you the generic link: selenium. FindElement(By. XPath("xpath=//a[contains(@href,'listDetails.do')")).
Should be something similar to:
//a[text()='text_i_want_to_find']/@href
Too late for you, but for anyone else with the same question...
//a[contains(text(), 'programming')]/@href
Of course, 'programming' can be any text fragment.
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