I've found out that people use JQuery element-locators in Selenium. I like the idea and I'd like to ask about benefits from using JQuery selectors instead of XPath ones. Are they more "flexible" or fast, let's say in Firefox or Google Chrome?
2 Answers
Based on my small experience with selenium I have some arguments against XPath:
XPath is slow in FireFox and painfully slow in IE (I have observations on IE7). My tests which use mostly XPath run ~2.5 times slower in IE7 than in FF.
With XPath selectors you are more likely to run into browser dependent problems. I have two examples:
- this question XPath expression for disabled input in IE7. Testing with Selenium that nobody could answer so far.
- I could not locate the text in a hidden span in a browser independent way.
I hope this was useful.
Cheers!
3 Comments
Vitaliy
Many thanks for your answer. Have you tried using JQuery locators?
Lachezar Balev
Nope. We used DOM locators several times. They are much faster and reliable than XPath but tend to be more difficult to create and maintain as you can see in my post :-)
Chris Noe
Concur painfully slow in IE. But what is your basis for saying that XPath is slow in Firefox? I have done lots of measuring (2GHz PC), and I see 0-2ms for most expressions, and 10s of ms for very complex/nested expressions.