JBoss Community Archive (Read Only)

Graphene 1

Locators

Locator

When writing selenium test cases, you are working with locators all the time.

All the locators are encapsulated as instances of Locator interface, divided into two main groups: ElementLocators and AttributeLocators.

Element Locator

Separated by location strategies to following types:

  • JQuery implements Iterable, Compoundable

  • XPath  implements Iterable, Compoundable

  • CSS implements Compoundable

  • ID

  • DOM

  • Link

  • Name

  • Identifier (ID or name)

Iterable Locator

Iterable locator means that you can refer to list of its children (Iterable<ElementLocator>).

JQueryLocator myTable = jq("#mytable");
JQueryLocator rows = myTable.getChild(jq("tr"));

 
for (JQueryLocator row :  rows) {
   ...
}

Compoundable Locator

Compoundable locator signs that you are able to use original expression and some partial expression to derive new composite expression. That way you can desribe the structure of your tested DOM tree in manner of reusability.

JQueryLocator cellLink = cell.getChild(jq("span.link a"));

It's obvious that by composing and iterating over locator's descendants you can only use and derive the same type of locator!

Note: it is not case of WebDriver / Selenium 2.0 location strategy - this framework uses the direct references to elements, so you can use each element again to derive new element by referring to it, using whatever location strategy you want - but this is quite problematic in testing AJAX-based frameworks, since the reference can quickly became stale after interaction with page.

You can also see that use of type-safe locators is quite verbose - you can then use the capabilities of Graphene utility class as locator factory.

Attribute Locator

Creating  attribute locators  is also very straight forward. When you want to refer to attribute's value, you need some element locator first as the base for deriving locator: 

jq("#foo-link").getAttribute(CLASS);
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:13:26 UTC, last content change 2012-03-16 14:26:02 UTC.