0 votes
1 view
in Devops and Agile by (19.8k 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 (63.4k points)

It can be done by using CSS selectors.‚Äč

The code would be:

driver.findElement(By.cssSelector("a[href*='long']")).click();

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...