Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

The following are a bunch of links <a elements. ONLY one of them has a substring "long" as a value for the attribute href

<a class="c1" href= "very_lpng string" > name1 </a>

<a class="g2" href= "verylong string" > name2 </a>   // The one that I need

<a class="g4" href= "very ling string" > name3 </a>

<a class="g5g" href= "very ng string" > name4 </a>


I need to click the link who href has substring "long" in it. How can I do this?

PS: driver.findElement(By.partialLinkText("long")).click(); // b/c it chooses by the name

1 Answer

0 votes
by (62.9k points)

It can be done by using CSS selectors.​

The code would be:


Hope this helps!

Browse Categories