Element Locating Strategy

A good element locating strategy shall be:

  • efficient: WebDriver shall find it fast
  • resilient: element-locating code can sustain the many changes that developers are going to make to the page
  • have good readability: No miles-long xpath strings or css selector strings in the code

How can we achieve that?

  • Preferred selector order : id > name > css > xpath
  • Work with Development team to add ID to all web elements, well, if this is not feasible, ask for ID for all new elements from now on.
  • If we have to locate elements vis css selector, Jump-locate it
  • If we have to use xpath, Make Xpath Brief and Concise via Jump-Locating
  • Avoid locating element via its text content.

Leave a Reply

Your email address will not be published. Required fields are marked *