Siva
Siva

Reputation: 1198

Which type of locator (like ID, xpath, class name etc) is good to use in selenium automation

We can locate an element in webpage using ID, xpath, class name, tag, name, link text,attribute etc

Using which kind of locator selenium detects the element faster. Also which type of locator is good to use(faster to access and reliable)

Upvotes: 0

Views: 2481

Answers (2)

gaurav panwar
gaurav panwar

Reputation: 44

In My Experience following is order when it comes to search time of objects.

Link Text : fastest way to search its so fast some time you have to use wait for controlling it and works same for all browsers But you need to make sure that the text content has been loaded so it will fail if your page is too much bulky

CSS path: Its Also very fast but slightly less faster then Link Text But believe me it is a nightmare to edit css paths as you won't be easily able to find if a user changed class name "xyz" to "btw"

ID/Name : ID is supposed to be unique for an element . IF your developers are following the standard way then it is best .its equal to CSS path when it comes to speed

Xpath: (Slowest of all and second problem with XPATH is every browser has Different syntax like IE it has some other type of expression when compared with FF or chrome I always avoid using Xpath) But if you have written strict xpaths then your code will work like a charm. Xpaths enhance your capability to get any elemnt and are the most widely used.

http://www.seleniumhq.org/docs/03_webdriver.jsp#locating-ui-elements-webelements

Upvotes: 1

fahad
fahad

Reputation: 389

In My Experience following is order when it comes to search time of objects.

  1. Link Text : fastest way to search its so fast some time you have to use wait for controlling it and works same for all browsers
  2. CSS path: Its Also very fast but slightly less faster then Link Text
  3. ID/Name : its equal to CSS path when it comes to speed
  4. Xpath: Slowest of all and second problem with XPATH is every browser has Different syntax like IE it has some other type of expression when compared with FF or chrome I always avoid using Xpath

Upvotes: 0

Related Questions