Reputation: 1198
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
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
Reputation: 389
In My Experience following is order when it comes to search time of objects.
Upvotes: 0