View Javadoc

1   package com.atlassian.webdriver.waiter.webdriver.function.element;
2   
3   import com.atlassian.webdriver.waiter.webdriver.retriever.WebElementRetriever;
4   import com.atlassian.webdriver.waiter.webdriver.function.ConditionFunction;
5   import org.openqa.selenium.NoSuchElementException;
6   import org.openqa.selenium.StaleElementReferenceException;
7   import org.openqa.selenium.WebDriver;
8   
9   /**
10   * @since 2.1.0
11   */
12  public class ExistsFunction implements ConditionFunction
13  {
14      private final WebElementRetriever elementRetriever;
15  
16      public ExistsFunction(final WebElementRetriever elementRetriever)
17      {
18          this.elementRetriever = elementRetriever;
19      }
20  
21      public Boolean apply(WebDriver from)
22      {
23          try
24          {
25              // Make any call on the element.
26              elementRetriever.retrieveElement().isDisplayed();
27              return true;
28          }
29          catch (NoSuchElementException e)
30          {
31              return false;
32          }
33          catch (StaleElementReferenceException e)
34          {
35              return false;
36          }
37      }
38  }