MxfrdA
MxfrdA

Reputation: 171

Select by href starting by a string

I'm looking for a solution of my problem. I want to find all the href elements of my web page starting by

href="/lite/..... "

I want to check the http status of all my href starting by /lite/ My test is in Java and I'm using selenium

Any ideas ?

Thanks

Upvotes: 0

Views: 63

Answers (2)

Florent B.
Florent B.

Reputation: 42528

You could use a CSS selector:

elements = driver.findElements(By.cssSelector("[href^='/lite/']"));

Note that it doesn't return the links for a frame element.

Upvotes: 1

f1sh
f1sh

Reputation: 11942

Can you use XPath? Then you could use something like:

//*[starts-with(@href,'/lite')]

Upvotes: 1

Related Questions