Since we say that IDs are faster and are preferred over XPaths, how different would the execution of the following be?
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.Sign up to join this community
When you are looking for an element by id, this is going to eventually come down to
document.getElementById() execution which is blazingly fast and highly optimized by the modern browsers.
XPath location strategy in this case requires traversing the whole HTML tree even though having the id attribute check is usually optimized in XPath engines.
It depends what you mean by different. Best practice would be to use a static ID of some kind, either whether a test ID or through an element ID - as long as it's 1) unique and 2) static.
XPath isn't ideal as it's relative to other elements on the page, meaning it's liable to change fairly often.