View Javadoc

1   package com.atlassian.webdriver.waiter.webdriver.retriever;
2   
3   import com.google.common.base.Preconditions;
4   
5   /**
6    * @since 2.1.0
7    */
8   public class WebElementFieldRetriever
9   {
10  
11      private final Supplier<String> fieldSupplier;
12  
13      private WebElementFieldRetriever(Supplier<String> fieldSupplier)
14      {
15          this.fieldSupplier = Preconditions.checkNotNull(fieldSupplier, "The field supplier can not be null.");
16      }
17  
18      public static WebElementFieldRetriever newTextRetriever(final WebElementRetriever webElementRetriever)
19      {
20          Preconditions.checkNotNull(webElementRetriever, "The web element retriever can not be null.");
21          return new WebElementFieldRetriever(new Supplier<String>()
22          {
23              @Override
24              public String supply()
25              {
26                  return webElementRetriever.retrieveElement().getText();
27              }
28          });
29      }
30  
31      public static WebElementFieldRetriever newAttributeRetriever(final WebElementRetriever webElementRetriever,
32              final String fieldName)
33      {
34          Preconditions.checkNotNull(webElementRetriever, "The web element retriever can not be null.");
35          Preconditions.checkNotNull(fieldName, "The field name can not be null.");
36          return new WebElementFieldRetriever(new Supplier<String>()
37          {
38              @Override
39              public String supply()
40              {
41                  return webElementRetriever.retrieveElement().getAttribute(fieldName);
42              }
43          });
44      }
45  
46      public String retrieveField()
47      {
48          return fieldSupplier.supply();
49      }
50  }