Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
244 views
by Contributing Tester (42 points)
retagged by
Hi,
Which one is best CSSSelector or Xpath in selenium webdriver Java to identify Objects? other than Id of object

Generally I used to use Xpath but nowadays it makes script execution slow.

Hoping for best answer

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

XPath vs CSS is very old debate. Earlier it made sense to use CSS Selector over xPath as it was much faster. But latest browsers are coming up with more optimized JavaScript engine which are much faster. So, you can make use of any of CSS Selector or xPath. Just mind that if you use CSS selector, you should not use nth-child as many of IE versions does not support nth-child and you may have to refractor your code to use xPath.

To to use CSS Selector or xPath is something depends on your application complexity and browsers you are planning to use for test automation.

Let me know your further points in comments.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...