LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

Why should I choose CSS selectors over other element identifiers in Selenium Automation?

I have read somewhere that we should choose CSS selectors over other element identifiers in Selenium Automation. Can someonw please tell me the reasons?

Up Vote Down Vote 0 Votes
Posted 5 months ago

Answers


You don’t have to use CSS all the time. The order you have to follow is,

If your target is single element

id - name - css Selector - xpath(Relative)

If your target is multiple elements

className - tagName - css Selector - xpath(Relative)

If your target element is a link with shorter link text

linkText - href

If your target element is a link with longer link text

partialLinkText - href

Up Vote Down Vote 3 Votes
Posted 5 months ago