-2

I have just started to learn selenium ide and get to know that there are many locators such as ID, Name, CSS, Link, Xpath, DOM To find out the elements. What is the Best locator to find out the elements in a page?

  • gets some idea regarding the css & xpath http://stackoverflow.com/questions/16788310/what-is-the-difference-between-css-selector-xpath-which-is-betteraccording-t – Chetan Jul 02 '14 at 07:34

1 Answers1

2

Each locaters have pros & cons, better way to use according to your requirement. The following post will help you,

  • ID :- Pros - Each id is supposed to be unique so no chance of matching several elements. Cons - Works well only on elements with fixed ids and not generated ones

  • Name:- PROS: Works well with fixed list of similar elements CONS: Difficult to use with data-bound lists.

  • Link:- PROS: Will only select anchor elements Useful when testing navigation CONS: You have to know the text of the link before.

  • DOM:- PROS: Javascript allows you to build dynamic locators CONS: Relies on the structure of the page

  • Xpath:- PROS: Allows very precise locators CONS: Slower than CSS. Relies on browser?s XPath implementation which is not always complete (especially on IE) and as such is not recommended for cross-browser testing

  • Css:- PROS: Much faster than XPath. Widely used. Provides a good balance between structure and attributes. Allows for selection of elements by their surrounding context CONS: They tend to be more complex and require a steeper learning curve

Chetan
  • 2,360
  • 3
  • 18
  • 33