Should I Always Try to Select Element with XPath?

apex1

Regular Member
Joined
May 29, 2015
Messages
217
Reaction score
182
I'm wondering how often should I use XPath?

I can also select by ID / name / CSS etc.

Are there any downsides to always using XPath?

Should I always use it with 2 elements when possible?
 
It depends. Xpath should only be used in where name or id are dynamic(changes randomly). Downside of xpath is that it uses more cpu cycle. Are developing any bot?
 
XPath can use ID and other selectors too. This decision is case-by-case basis and depends on the site and how it changes. Sometimes websites generate new IDs on every load but sometimes not and so ID can be brilliantly easy since it's unique.
 
Back
Top