What is the best way to detect an element on a webpage for automated testing using SeleniumRC using Java?. I know that there are XPath elements and CSS elements, but which one is best?
thanks!
Nitin
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In my opinion, the most accurate way is XPath as you can use XPath’s to describe the exact position of an element within the DOM, however there are some instances where CSS locators work better than XPaths.
Using selenium’s ID locator is the most simple, but unless the element you are looking for has an ID not always useful.
The biggest negative when using XPath’s is the performance with Selenium RC and browsers with bad JavaScript rendering engines (Think IE6/IE7). Quite a bit of work has been dome to try and rectify this so if you use well formed XPath’s that only search specific parts of the DOM this problem should be minimal. The Selenium webdriver implementation is much faster.
The summary is really there is no one answer it depends what you want out of a locator, and which browsers you are testing. I personally use XPath in 99% of instances.
I personally use XPath almost exclusively with the occasional CSS locator.