This question have been asked and answered in numerous forums in different formats. Considering them all if we prioritize the locators the list would be as follows :
- id: Select element with the specified
- name: Select first element with the specified
- link_text: Select link (anchor tag) element which contains text matching the specified
- partial_link_text: Select link (anchor tag) element which contains text matching the specified
- tag_name: Locate Element using a
- class_name: Locate Element using a
- css_selector: Select the element using
- xpath: Locate an element using an
So the question now is Whats New?
The answer is Selenium have evolved a lot recently.
WebDriver is now a
W3C Recommendation Candidate. Things within
Selenium are changing pretty fast. It’s no more only about choosing the locator. We need to use a locator which will :
- Uniquely identify an element.
- The performance of the locator must be optimized.
Keeping these two factors in mind, the best strategy would be to Mock the DOM. The
W3C Recommendation Candidate does mentions the list of the locators as per the below :
So the verdict is clear and concise.