Groovy Documentation

geb.navigator
[Groovy] Class Navigator

java.lang.Object
  geb.navigator.Navigator
All Implemented Interfaces:
Iterable

abstract class Navigator
extends Object

Navigator is a jQuery-style DOM traversal tool that wraps a set of WebDriver WebElements. The code is based on the Doj library written by Kevin Wetzels: http://code.google.com/p/hue/


Property Summary
Browser browser

 
Constructor Summary
Navigator(Browser browser)

 
Method Summary
Navigator add(String selector)

Navigator add(WebElement[] elements)

Navigator add(Collection elements)

Collection allElements()

Returns all context elements.

boolean asBoolean()

String attr(String name)

Returns the value of the given attribute of the first context element.

Navigator children()

Navigator children(String selector)

List classes()

Returns the class names present on all elements.

void click()

Clicks on the first context element.

void click(Class pageClass)

void click(List potentialPageClasses)

Navigator closest(String selector)

Creates a new Navigator instance containing the first ancestor element of each of the current context elements that match the selector.

Navigator eq(int index)

Gets the wrapped element at the given index.

Navigator filter(String selector)

Filters the set of elements represented by this Navigator to include only those that match the selector.

Navigator filter(Map predicates)

Navigator filter(Map predicates, String selector)

Navigator find(String selector)

Creates a new Navigator instance containing the elements matching the given CSS selector.

Navigator find(String selector, int index)

Shorthand for find(selector)[indexOfElement].

Navigator find(Map predicates)

Creates a new Navigator instance containing the elements whose attributes match the specified values or patterns.

Navigator find(Map predicates, String selector)

Selects elements by both CSS selector and attributes.

Navigator findAll(Closure predicate)

Overrides the standard Groovy findAll so that the object returned is a Navigator rather than a Collection.

Navigator first()

Creates a new Navigator instance containing only the first context element (wrapped).

WebElement firstElement()

Returns the first context element (not wrapped).

Navigator getAt(int index)

Gets the wrapped element at the given index.

Navigator getAt(Range range)

Gets the wrapped elements in the given range.

Navigator getAt(Collection indexes)

Gets the wrapped elements at the given indexes.

String getAttribute(String name)

Returns the value of the given attribute of the first context element.

protected WebElement getElement(int index)

Gets the element at the given index.

protected List getElements(Range range)

Gets the elements in the given range.

protected List getElements(Collection indexes)

Gets the elements at the given indexes.

int getHeight()

Returns the height of the first element the navigator matches or 0 if it matches nothing.

JQueryAdapter getJquery()

Returns an adapter for calling jQuery methods on the elements in this navigator.

int getWidth()

Returns the width of the first element the navigator matches or 0 if it matches nothing.

int getX()

Returns the x coordinate (from the top left corner) of the first element the navigator matches or 0 if it matches nothing.

int getY()

Returns the y coordinate (from the top left corner) of the first element the navigator matches or 0 if it matches nothing.

Navigator has(String selector)

Filters the set of elements represented by this Navigator to include only that have one or more descendants that match the selector.

boolean hasClass(String className)

Returns true if at least one of the context elements has the given class.

Navigator head()

Creates a new Navigator instance containing only the first context element (wrapped).

boolean is(String tag)

Returns true if at least one of the context elements matches the tag.

boolean isDisabled()

Shorthand for hasAttribute("disabled").

boolean isDisplayed()

Uses the isDisplayed() of RenderedWebElement to determine if the first element in the context is displayed.

boolean isEmpty()

Returns true when there are no context elements.

boolean isReadOnly()

Shorthand for hasAttribute("readonly").

Iterator iterator()

Navigator last()

Creates a new Navigator instance containing only the last context element (wrapped).

WebElement lastElement()

Returns the last context element (not wrapped).

Navigator leftShift(def value)

Navigator next()

Creates a new Navigator instance containing the next sibling elements of the current context elements.

Navigator next(String selector)

Creates a new Navigator instance containing the next sibling elements of the current context elements, matching the selector.

Navigator nextAll()

Creates a new Navigator instance containing all following sibling elements of the current context elements.

Navigator nextAll(String selector)

Creates a new Navigator instance containing all following sibling elements of the current context elements that match the selector.

Navigator nextUntil(String selector)

Creates a new Navigator instance containing all following sibling elements of the current context elements up to, but not including, the first to match the selector.

Navigator not(String selector)

Returns a new Navigator instance containing all elements of the current Navigator that do not match the selector.

static Navigator on(Browser browser, WebElement[] contextElements)

Factory method to create an initial Navigator instance.

static Navigator on(Browser browser, Navigator[] navigators)

Factory method to create a Navigator instance that is composed of other instances.

static Navigator on(Browser browser, Collection contextElements)

Factory method to create an initial Navigator instance.

static Navigator on(Browser browser)

Factory method to create an initial Navigator instance.

Navigator parent()

Creates a new Navigator instance containing the direct parent elements of the current context elements.

Navigator parent(String selector)

Creates a new Navigator instance containing the direct parent elements of the current context elements that match the selector.

Navigator parents()

Creates a new Navigator instance containing all the ancestor elements of the current context elements.

Navigator parents(String selector)

Creates a new Navigator instance containing all the ancestor elements of the current context elements that match the selector.

Navigator parentsUntil(String selector)

Creates a new Navigator instance containing all the ancestor elements of the current context elements up to but not including the first that matches the selector.

Navigator plus(Navigator navigator)

Merges the Navigator instance with the current instance to create a new Navigator instance containing the context elements of both.

Navigator prevAll()

Creates a new Navigator instance containing all preceding sibling elements of the current context elements.

Navigator prevAll(String selector)

Creates a new Navigator instance containing all preceding sibling elements of the current context elements, matching the selector.

Navigator prevUntil(String selector)

Creates a new Navigator instance containing all preceding sibling elements of the current context elements up to, but not including the first matching the selector.

Navigator previous()

Creates a new Navigator instance containing the previous sibling elements of the current context elements.

Navigator previous(String selector)

Creates a new Navigator instance containing the previous sibling elements of the current context elements, matching the selector.

Navigator remove(int index)

Creates a new Navigator instance by removing the element at the given index from the context.

Navigator siblings()

Navigator siblings(String selector)

int size()

Returns the number of context elements.

String tag()

Returns the tag name of the first context element.

Navigator tail()

Creates a new Navigator instance containing all but the first context element (wrapped).

String text()

Returns the text content of the first context element.

def value()

Returns the value of the first context element for input elements (including textarea, select and button).

Navigator value(def value)

Sets the value of the form input elements to the given value.

Navigator verifyNotEmpty()

Throws an exception when the Navigator instance is empty.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Property Detail

browser

final Browser browser


 
Constructor Detail

Navigator

Navigator(Browser browser)


 
Method Detail

add

Navigator add(String selector)


add

Navigator add(WebElement[] elements)


add

Navigator add(Collection elements)


allElements

Collection allElements()
Returns all context elements.
Returns:
all context elements


asBoolean

boolean asBoolean()


attr

String attr(String name)
Returns the value of the given attribute of the first context element.
Parameters:
name - name of the attribute
Returns:
the value of the given attribute of the first context element


children

Navigator children()


children

Navigator children(String selector)


classes

List classes()
Returns the class names present on all elements. The result is a unique set and is in alphabetical order.
Returns:
the class names present on all elements.


click

void click()
Clicks on the first context element.
throws:
java.io.IOException
throws:
java.lang.ClassCastException


click

void click(Class pageClass)


click

void click(List potentialPageClasses)


closest

Navigator closest(String selector)
Creates a new Navigator instance containing the first ancestor element of each of the current context elements that match the selector.

Unlike parent(), this method will keep traversing up the DOM until a match is found or the top of the DOM has been found

Parameters:
selector - to match
Returns:
new Navigator instance


eq

Navigator eq(int index)
Gets the wrapped element at the given index.

When no such element exists, an empty Navigator instance is returned.

Parameters:
index - index of the element to retrieve - pass a negative value to start from the back
Returns:
new Navigator instance


filter

Navigator filter(String selector)
Filters the set of elements represented by this Navigator to include only those that match the selector. Note that unlike find only tag, id and class based selectors are supported for this method regardless of the capabilities of the underlying WebDriver instance.
Parameters:
selector - a CSS selector
Returns:
a new Navigator instance


filter

Navigator filter(Map predicates)


filter

Navigator filter(Map predicates, String selector)


find

Navigator find(String selector)
Creates a new Navigator instance containing the elements matching the given CSS selector. Any CSS capabilities supported by the underlying WebDriver instance are supported. If the underlying WebDriver instance does not natively support finding elements by CSS selectors then tag, id and class name selectors may be applied (in any combination).

Examples:

h1
selects all 'h1' elements
.article
selects all elements with the class 'article'
#header
selects the element with the id 'header'
div.article p
selects all p elements that are descendants of a div with class 'article'
h1, h2
selects all h1 and h2 elements
li:odd
selects odd-numbered li elements (CSS3 selectors like this are only supported when supported by the underlying WebDriver instance)
Parameters:
selector - a CSS selector
Returns:
new Navigator instance containing the matched elements


find

Navigator find(String selector, int index)
Shorthand for find(selector)[indexOfElement].
Parameters:
selector - a CSS selector
index - index of the required element in the selection
Returns:
new Navigator instance containing a single element


find

Navigator find(Map predicates)
Creates a new Navigator instance containing the elements whose attributes match the specified values or patterns. The key 'text' can be used to match the text contained in elements. Regular expression Pattern objects may be used as values. Note that for selecting by class it is better to use a CSS selector.

Examples:

find(name: "firstName")
selects all elements with the name "firstName"
find(name: "firstName", readonly: "readonly")
selects all elements with the name "firstName" that are read-only
find(text: "I can has cheezburger")
selects all elements containing the exact text
find(text: ~/I can has.+/)
selects all elements whose text matches a regular expression
Parameters:
predicates - a Map with keys representing attributes and values representing required values or patterns
Returns:
a new Navigator instance containing the matched elements


find

Navigator find(Map predicates, String selector)
Selects elements by both CSS selector and attributes. For example find("input", name: "firstName") will select all input elements with the name "firstName".
Parameters:
selector - a CSS selector
predicates - a Map with keys representing attributes and values representing required values or patterns
Returns:
a new Navigator instance containing the matched elements


findAll

Navigator findAll(Closure predicate)
Overrides the standard Groovy findAll so that the object returned is a Navigator rather than a Collection.


first

Navigator first()
Creates a new Navigator instance containing only the first context element (wrapped).
Returns:
new Navigator instance


firstElement

WebElement firstElement()
Returns the first context element (not wrapped).
Returns:
the first context element (not wrapped)


getAt

Navigator getAt(int index)
Gets the wrapped element at the given index.

When no such element exists, an empty Navigator instance is returned.

Parameters:
index - index of the element to retrieve - pass a negative value to start from the back
Returns:
new Navigator instance


getAt

Navigator getAt(Range range)
Gets the wrapped elements in the given range.

When no such elements exist, an empty Navigator instance is returned.

Parameters:
range - range of the elements to retrieve
Returns:
new Navigator instance


getAt

Navigator getAt(Collection indexes)
Gets the wrapped elements at the given indexes.

When no such elements exist, an empty Navigator instance is returned.

Parameters:
indexes - indexes of the elements to retrieve
Returns:
new Navigator instance


getAttribute

String getAttribute(String name)
Returns the value of the given attribute of the first context element.
Parameters:
name - name of the attribute
Returns:
the value of the given attribute of the first context element


getElement

protected WebElement getElement(int index)
Gets the element at the given index.
Parameters:
index - index of the element to retrieve - pass a negative value to start from the back
Returns:
the element at the given index, or null if no such element exists


getElements

protected List getElements(Range range)
Gets the elements in the given range.
Parameters:
range - range of the elements to retrieve
Returns:
the elements in the given range, or an empty list if no such elements exist


getElements

protected List getElements(Collection indexes)
Gets the elements at the given indexes.
Parameters:
indexes - indexes of the elements to retrieve
Returns:
the elements at the given indexes, or an empty list if no such elements exist


getHeight

int getHeight()
Returns the height of the first element the navigator matches or 0 if it matches nothing.

To get the height of all matched elements you can use the spread operator navigator*.height


getJquery

JQueryAdapter getJquery()
Returns an adapter for calling jQuery methods on the elements in this navigator.


getWidth

int getWidth()
Returns the width of the first element the navigator matches or 0 if it matches nothing.

To get the width of all matched elements you can use the spread operator navigator*.width


getX

int getX()
Returns the x coordinate (from the top left corner) of the first element the navigator matches or 0 if it matches nothing.

To get the x coordinate of all matched elements you can use the spread operator navigator*.x


getY

int getY()
Returns the y coordinate (from the top left corner) of the first element the navigator matches or 0 if it matches nothing.

To get the y coordinate of all matched elements you can use the spread operator navigator*.y


has

Navigator has(String selector)
Filters the set of elements represented by this Navigator to include only that have one or more descendants that match the selector.
Parameters:
selector - a CSS selector
Returns:
a new Navigator instance


hasClass

boolean hasClass(String className)
Returns true if at least one of the context elements has the given class.
Parameters:
className - class to check for
Returns:
true if at least one of the context elements has the given class


head

Navigator head()
Creates a new Navigator instance containing only the first context element (wrapped).
Returns:
new Navigator instance


is

boolean is(String tag)
Returns true if at least one of the context elements matches the tag.
Parameters:
tag - tag to match
Returns:
true if at least one of the context elements matches the tag


isDisabled

boolean isDisabled()
Shorthand for hasAttribute("disabled").
Returns:
true when the first element is disabled


isDisplayed

boolean isDisplayed()
Uses the isDisplayed() of RenderedWebElement to determine if the first element in the context is displayed. If the context is empty, or the first element is not a RenderedWebElement, false will be returned.
Returns:
true if the first element is displayed


isEmpty

boolean isEmpty()
Returns true when there are no context elements.
Returns:
true when there are no context elements


isReadOnly

boolean isReadOnly()
Shorthand for hasAttribute("readonly").
Returns:
true when the first element is readonly


iterator

Iterator iterator()


last

Navigator last()
Creates a new Navigator instance containing only the last context element (wrapped).
Returns:
new Navigator instance


lastElement

WebElement lastElement()
Returns the last context element (not wrapped).
Returns:
the last context element (not wrapped)


leftShift

Navigator leftShift(def value)


next

Navigator next()
Creates a new Navigator instance containing the next sibling elements of the current context elements.
Returns:
new Navigator instance


next

Navigator next(String selector)
Creates a new Navigator instance containing the next sibling elements of the current context elements, matching the selector.

Unlike next(), this method will keep looking for the first matching sibling until it finds a match or is out of siblings.

Parameters:
selector - to match
Returns:
new Navigator instance


nextAll

Navigator nextAll()
Creates a new Navigator instance containing all following sibling elements of the current context elements.
Returns:
new Navigator instance


nextAll

Navigator nextAll(String selector)
Creates a new Navigator instance containing all following sibling elements of the current context elements that match the selector.

Unlike next(), this method will keep looking for the first matching sibling until it finds a match or is out of siblings.

Parameters:
selector - to match
Returns:
new Navigator instance


nextUntil

Navigator nextUntil(String selector)
Creates a new Navigator instance containing all following sibling elements of the current context elements up to, but not including, the first to match the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


not

Navigator not(String selector)
Returns a new Navigator instance containing all elements of the current Navigator that do not match the selector.
Parameters:
selector - a CSS selector
Returns:
a new Navigator instance


on

static Navigator on(Browser browser, WebElement[] contextElements)
Factory method to create an initial Navigator instance.

Hides the fact that there are two implementations of Navigator at work behind the scenes: one for working with an empty context that keeps the code for the other one, with most of the logic, simple.

Parameters:
browser - the browser the content is attached to
contextElements - the context elements to use
Returns:
new Navigator instance


on

static Navigator on(Browser browser, Navigator[] navigators)
Factory method to create a Navigator instance that is composed of other instances.
Parameters:
browser - the browser the content is attached to
navigators - the navigators to compose of
Returns:
new Navigator instance


on

static Navigator on(Browser browser, Collection contextElements)
Factory method to create an initial Navigator instance.

Hides the fact that there are two implementations of Navigator at work behind the scenes: one for working with an empty context that keeps the code for the other one, with most of the logic, simple.

Parameters:
browser - the browser the content is attached to
contextElements - the context elements to use
Returns:
new Navigator instance


on

static Navigator on(Browser browser)
Factory method to create an initial Navigator instance.

Hides the fact that there are two implementations of Navigator at work behind the scenes: one for working with an empty context that keeps the code for the other one, with most of the logic, simple.

Parameters:
browser - the browser for which to create a navigator of it's entire content
Returns:
new Navigator instance


parent

Navigator parent()
Creates a new Navigator instance containing the direct parent elements of the current context elements.
Returns:
new Navigator instance


parent

Navigator parent(String selector)
Creates a new Navigator instance containing the direct parent elements of the current context elements that match the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


parents

Navigator parents()
Creates a new Navigator instance containing all the ancestor elements of the current context elements.
Returns:
new Navigator instance


parents

Navigator parents(String selector)
Creates a new Navigator instance containing all the ancestor elements of the current context elements that match the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


parentsUntil

Navigator parentsUntil(String selector)
Creates a new Navigator instance containing all the ancestor elements of the current context elements up to but not including the first that matches the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


plus

Navigator plus(Navigator navigator)
Merges the Navigator instance with the current instance to create a new Navigator instance containing the context elements of both.
Parameters:
navigator - navigator to merge with this one
Returns:
new Navigator instance


prevAll

Navigator prevAll()
Creates a new Navigator instance containing all preceding sibling elements of the current context elements.
Returns:
new Navigator instance


prevAll

Navigator prevAll(String selector)
Creates a new Navigator instance containing all preceding sibling elements of the current context elements, matching the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


prevUntil

Navigator prevUntil(String selector)
Creates a new Navigator instance containing all preceding sibling elements of the current context elements up to, but not including the first matching the selector.
Parameters:
selector - to match
Returns:
new Navigator instance


previous

Navigator previous()
Creates a new Navigator instance containing the previous sibling elements of the current context elements.
Returns:
new Navigator instance


previous

Navigator previous(String selector)
Creates a new Navigator instance containing the previous sibling elements of the current context elements, matching the selector.

Unlike previous(), this method will keep looking for the first matching sibling until it finds a match or is out of siblings.

Parameters:
selector - to match
Returns:
new Navigator instance


remove

Navigator remove(int index)
Creates a new Navigator instance by removing the element at the given index from the context.

If no such element exists, the current instance is returned.

Parameters:
index - index of the element to remove - pass a negative value to start from the back
Returns:
new Navigator instance


siblings

Navigator siblings()


siblings

Navigator siblings(String selector)


size

int size()
Returns the number of context elements.
Returns:
the number of context elements


tag

String tag()
Returns the tag name of the first context element.
Returns:
the tag name of the first context element


tail

Navigator tail()
Creates a new Navigator instance containing all but the first context element (wrapped).
Returns:
new Navigator instance


text

String text()
Returns the text content of the first context element.
Returns:
the text content of the first context element


value

def value()
Returns the value of the first context element for input elements (including textarea, select and button).

In the case of a select, the value of the first selected option is returned.

Returns:
value of the first context element


value

Navigator value(def value)
Sets the value of the form input elements to the given value.
Parameters:
value - value to use
Returns:
current Navigator instance


verifyNotEmpty

Navigator verifyNotEmpty()
Throws an exception when the Navigator instance is empty.
Returns:
the current Navigator instance


 

Groovy API Documentation for geb-core 0.6.3 - Licensed under the Apache License, Version 2.0 - http://www.gebish.org