import org.jboss.arquillian.graphene.findby.FindByJQuery; @FindByJQuery(".foo-class:eq(0)") private WebElement customElement;
You can leverage JQuery Selectors API to locate your elements.
import org.jboss.arquillian.graphene.findby.FindByJQuery; @FindByJQuery(".foo-class:eq(0)") private WebElement customElement;
The above code will locate the the first element with the class 'foo-class'.
This locating strategy requires JQuery to be installed to the page. Graphene installs it in a no conflict way automatically if it is needed (jquery locating strategy is used and it has not been installed yet). Note that it can have small performance impact, because the installation of the JQuery library can take some time. Therefore, locating by id, css, or className is preferred if possible or when you care about that 1 sec which it takes usually.
Sometimes it is handy to locate your elements which are inferred from the root of the document. It can be especially used in Page Fragments, where all defined @FindBy and the @FindByJQuery annotations are inferred from the root of that Page Fragment.
To infer them from the root of the document just start their locators with html, head, or body expression. For example:
@FindByJQuery("body div:visible") private WebElement firstVisibleDiv;