Using Selenium WebDriver, while finding an element in HTML, why are XPaths considered to be slower than CSS selectors? I generally use XPaths and dynamic XPaths.
Can anyone logically explain me in detail?
Using Selenium WebDriver, while finding an element in HTML, why are XPaths considered to be slower than CSS selectors? I generally use XPaths and dynamic XPaths.
Can anyone logically explain me in detail?
While this is impossible to answer precisely except for specific test cases, maybe a general answer can help a little. CSS is a rather constrained (though increasingly expressive, with more recent CSS versions) expression language that allows the evaluation of CSS selectors to be easily optimized. XPath, on the other hand, is a generalized and complex expression language, that allows much more selections than CSS, and thus is harder to optimize. So while in theory for equivalent XPath/CSS expressions a perfectly optimizing XPath engine should be able to achieve the same performance as an CSS engine, in practice in many cases XPath optimization will be sup-optimal, and thus CSS will be faster.