Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Selenium by (19.7k points)
recategorized by

I'm trying to locate a link using Selenium Webdriver. I don't wanna locate it by link text, only the actual link which is typed in. This can be done by using Selenium's find element by XPath - method, but what is the syntax when I only know the starting of that href text, not the whole text?

I guess I'm searching for XPath link locator with some sort of starts with-method. I have no code ready on this.

1 Answer

0 votes
by (62.9k points)

You can use the start-with in XPath to locate an attribute value that helps you find an element that contains a particular text.

Take an example where you have the below-shown link on the page:

<a href="mylink_somerandomstuff">link text</a>

After that, use the following XPath to find links that have an href link that starts with 'mylink':

//a[starts-with(@href, "mylink")]

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...