org.openqa.selenium.support.pagefactory
Class AjaxElementLocator

java.lang.Object
  extended by org.openqa.selenium.support.pagefactory.DefaultElementLocator
      extended by org.openqa.selenium.support.pagefactory.AjaxElementLocator
All Implemented Interfaces:
ElementLocator

public class AjaxElementLocator
extends DefaultElementLocator

An element locator that will wait for the specified number of seconds for an element to appear, rather than failing instantly if it's not present. This works by polling the UI on a regular basis. The element returned will be present on the DOM, but may not actually be visible: override isElementUsable(WebElement) if this is important to you. Because this class polls the interface on a regular basis, it is strongly recommended that users avoid locating elements by XPath.


Field Summary
protected  int timeOutInSeconds
           
 
Constructor Summary
AjaxElementLocator(Clock clock, WebDriver driver, Field field, int timeOutInSeconds)
           
AjaxElementLocator(WebDriver driver, Field field, int timeOutInSeconds)
          Main constructor.
 
Method Summary
 WebElement findElement()
          Find the element.
protected  boolean isElementUsable(WebElement element)
          By default, elements are considered "found" if they are in the DOM.
protected  long sleepFor()
          By default, we sleep for 250ms between polls.
 
Methods inherited from class org.openqa.selenium.support.pagefactory.DefaultElementLocator
findElements
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeOutInSeconds

protected final int timeOutInSeconds
Constructor Detail

AjaxElementLocator

public AjaxElementLocator(WebDriver driver,
                          Field field,
                          int timeOutInSeconds)
Main constructor.

Parameters:
driver - The WebDriver to use when locating elements
field - The field representing this element
timeOutInSeconds - How long to wait for the element to appear. Measured in seconds.

AjaxElementLocator

public AjaxElementLocator(Clock clock,
                          WebDriver driver,
                          Field field,
                          int timeOutInSeconds)
Method Detail

findElement

public WebElement findElement()
Find the element. Will poll the interface on a regular basis until the element is present.

Specified by:
findElement in interface ElementLocator
Overrides:
findElement in class DefaultElementLocator

sleepFor

protected long sleepFor()
By default, we sleep for 250ms between polls. You may override this method in order to change how it sleeps.

Returns:
Duration to sleep in milliseconds

isElementUsable

protected boolean isElementUsable(WebElement element)
By default, elements are considered "found" if they are in the DOM. Override this method in order to change whether or not you consider the elemet loaded. For example, perhaps you need the element to be displayed:


Copyright © 2013. All Rights Reserved.