Class 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

      Fields 
      Modifier and Type Field Description
      protected int timeOutInSeconds  
    • Constructor Summary

      Constructors 
      Constructor Description
      AjaxElementLocator​(java.time.Clock clock, org.openqa.selenium.SearchContext context, int timeOutInSeconds, AbstractAnnotations annotations)  
      AjaxElementLocator​(java.time.Clock clock, org.openqa.selenium.SearchContext searchContext, java.lang.reflect.Field field, int timeOutInSeconds)  
      AjaxElementLocator​(org.openqa.selenium.SearchContext context, int timeOutInSeconds, AbstractAnnotations annotations)
      Use this constructor in order to process custom annotaions.
      AjaxElementLocator​(org.openqa.selenium.SearchContext searchContext, java.lang.reflect.Field field, int timeOutInSeconds)
      Main constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.openqa.selenium.WebElement findElement()
      Find the element.
      java.util.List<org.openqa.selenium.WebElement> findElements()
      Find the element list.
      protected boolean isElementUsable​(org.openqa.selenium.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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • timeOutInSeconds

        protected final int timeOutInSeconds
    • Constructor Detail

      • AjaxElementLocator

        public AjaxElementLocator​(org.openqa.selenium.SearchContext context,
                                  int timeOutInSeconds,
                                  AbstractAnnotations annotations)
        Use this constructor in order to process custom annotaions.
        Parameters:
        context - The context to use when finding the element
        timeOutInSeconds - How long to wait for the element to appear. Measured in seconds.
        annotations - AbstractAnnotations class implementation
      • AjaxElementLocator

        public AjaxElementLocator​(java.time.Clock clock,
                                  org.openqa.selenium.SearchContext context,
                                  int timeOutInSeconds,
                                  AbstractAnnotations annotations)
      • AjaxElementLocator

        public AjaxElementLocator​(org.openqa.selenium.SearchContext searchContext,
                                  java.lang.reflect.Field field,
                                  int timeOutInSeconds)
        Main constructor.
        Parameters:
        searchContext - The context to use when finding the element
        field - The field representing this element
        timeOutInSeconds - How long to wait for the element to appear. Measured in seconds.
      • AjaxElementLocator

        public AjaxElementLocator​(java.time.Clock clock,
                                  org.openqa.selenium.SearchContext searchContext,
                                  java.lang.reflect.Field field,
                                  int timeOutInSeconds)
    • Method Detail

      • findElements

        public java.util.List<org.openqa.selenium.WebElement> findElements()
        Find the element list. Will poll the interface on a regular basis until at least one element is present.
        Specified by:
        findElements in interface ElementLocator
        Overrides:
        findElements 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​(org.openqa.selenium.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 element loaded. For example, perhaps you need the element to be displayed:
        
           return element.isDisplayed();
         
        Parameters:
        element - The element to use
        Returns:
        Whether or not it meets your criteria for "found"