Official locator strategies for the webdriver Official locator strategies for the webdriver google-chrome google-chrome

Official locator strategies for the webdriver


Yes, you saw it right.

As per the current WebDriver - W3C Candidate Recommendation the Locator Strategies enlisted are as follows :

  • "css selector" : CSS selector
  • "link text" : Link text selector
  • "partial link text" : Partial link text selector
  • "tag name" : Tag name
  • "xpath" : XPath selector

Snapshot :

Locator Strategies

However, the JsonWireProtocol was once used to support the Locator Strategies enlisted below but currently the documentation clearly states it's Status as OBSOLETE :

  • class name : Returns an element whose class name contains the search value; compound class names are not permitted.
  • css selector : Returns an element matching a CSS selector.
  • id : Returns an element whose ID attribute matches the search value.
  • name : Returns an element whose NAME attribute matches the search value.
  • link text : Returns an anchor element whose visible text matches the search value.
  • partial link text : Returns an anchor element whose visible text partially matches the search value.
  • tag name : Returns an element whose tag name matches the search value.
  • xpath : Returns an element matching an XPath expression. The provided XPath expression must be applied to the server "as is"; if the expression is not relative to the element root, the server should not modify it. Consequently, an XPath query may return elements not contained in the root element's subtree.

Snapshot :

Locator Strategies

The change was propagated through the respective client specific bindings. For the Selenium-Java clients here is the client code where we have the switchcase working for the users :

        switch (using) {          case "class name":            toReturn.put("using", "css selector");            toReturn.put("value", "." + cssEscape(value));            break;          case "id":            toReturn.put("using", "css selector");            toReturn.put("value", "#" + cssEscape(value));            break;          case "link text":            // Do nothing            break;          case "name":            toReturn.put("using", "css selector");            toReturn.put("value", "*[name='" + value + "']");            break;          case "partial link text":            // Do nothing            break;          case "tag name":            toReturn.put("using", "css selector");            toReturn.put("value", cssEscape(value));            break;          case "xpath":            // Do nothing            break;        }        return toReturn;