1 package com.atlassian.webdriver.utils.element;
2
3 import com.atlassian.webdriver.utils.Check;
4 import org.apache.commons.lang.Validate;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.SearchContext;
7 import org.openqa.selenium.WebDriver;
8 import org.openqa.selenium.support.ui.ExpectedCondition;
9
10
11
12
13
14 abstract class ElementLocationCondition implements ExpectedCondition<Boolean>
15 {
16 enum Locatable
17 {
18 LOCATED,
19 NOTLOCATED
20 }
21
22 private final By by;
23 private final SearchContext at;
24 private final Locatable locatable;
25
26 ElementLocationCondition(By by, Locatable locatable)
27 {
28 this(by, null, locatable);
29 }
30
31 ElementLocationCondition(By by, SearchContext at, Locatable locatable)
32 {
33 Validate.notNull(by, "by cannot be null.");
34
35 this.by = by;
36 this.at = at;
37 this.locatable = locatable;
38 }
39
40 public Boolean apply(WebDriver webDriver)
41 {
42 if (locatable.equals(Locatable.LOCATED))
43 {
44 return Check.elementExists(by, at == null ? webDriver : at);
45 }
46 else
47 {
48 return !Check.elementExists(by, at == null ? webDriver : at);
49 }
50 }
51 }