1   package com.atlassian.selenium.pageobjects;
2   
3   import com.atlassian.selenium.SeleniumClient;
4   
5   public class PageElement {
6       protected final String locator;
7       protected final SeleniumClient client;
8       protected final String key;
9       protected final boolean autogeneratedKey;
10  
11  
12      private PageElement(String locator, String key, boolean autogeneratedKey, SeleniumClient client)
13      {
14          this.locator = locator;
15          this.client = client;
16          this.key = key;
17          this.autogeneratedKey = autogeneratedKey;
18      }
19  
20      public PageElement(String locator, String key, SeleniumClient client)
21      {
22          this(locator, key, false, client);
23      }
24  
25      public PageElement(String locator, SeleniumClient client)
26      {
27          this(locator, locator, true, client);
28      }
29  
30      public boolean isPresent()
31      {
32          return client.isElementPresent(locator);
33      }
34  
35      public void click()
36      {
37          client.click(locator);
38      }
39  
40      public String getLocator()
41      {
42          return locator;
43      }
44  
45      public String toString()
46      {
47          return locator;
48      }
49  
50      public String getText()
51      {
52          return client.getText(locator);
53      }
54  
55      public int getPositionTop()
56      {
57          return client.getElementPositionTop(locator).intValue();
58      }
59  
60      public int getPositionLeft()
61      {
62          return client.getElementPositionLeft(locator).intValue();
63      }
64  
65      public int getWidth()
66      {
67          return client.getElementWidth(locator).intValue();
68      }
69  
70      public int getHeight()
71      {
72          return client.getElementHeight(locator).intValue();
73      }
74  
75      public void contextMenu(PageElement element)
76      {
77          client.contextMenu(element.getLocator());
78      }
79  
80      public void doubleClick()
81      {
82          client.doubleClick(getLocator());
83      }
84  
85      public void dragAndDrop(String movementsString)
86      {
87          client.dragAndDrop(getLocator(), movementsString);
88      }
89  
90      public void dragAndDropToObject(PageElement dest)
91      {
92          client.dragAndDropToObject(getLocator(), dest.getLocator());
93      }
94  
95      public void focus()
96      {
97          client.focus(getLocator());
98      }
99  
100     public void getCursorPosition()
101     {
102         client.getCursorPosition(getLocator());
103     }
104 
105     public Number getIndex()
106     {
107         return client.getElementIndex(getLocator());
108     }
109 
110 
111     public void highlight()
112     {
113         client.highlight(getLocator());
114     }
115 
116 
117     public void mouseDown()
118     {
119         client.mouseDown(getLocator());
120     }
121 
122     public void mouseDownRight()
123     {
124         client.mouseDownRight(getLocator());
125     }
126 
127     public void mouseMove()
128     {
129         client.mouseDown(getLocator());
130     }
131 
132     public void mouseOut()
133     {
134         client.mouseOut(getLocator());
135     }
136 
137     public void mouseOver()
138     {
139         client.mouseOver(getLocator());
140     }
141 
142     public void mouseUp()
143     {
144         client.mouseUp(getLocator());
145     }
146 
147     public void mouseUpRight()
148     {
149         client.mouseUpRight(getLocator());
150     }
151 
152     public boolean isVisible()
153     {
154         return client.isElementPresent(getLocator()) && client.isVisible(getLocator());
155     }
156 
157     public boolean isEditable()
158     {
159         return client.isEditable(getLocator());
160     }
161 
162     public void keyDown(String keyCode)
163     {
164         client.keyDown(getLocator(), keyCode);
165     }
166 
167     public void keyPress(String keyCode)
168     {
169         client.keyPress(getLocator(), keyCode);
170     }
171 
172     public void keyUp(String keyCode)
173     {
174         client.keyUp(getLocator(), keyCode);
175     }
176     
177     public void type(String value)
178     {
179         client.type(getLocator(), value);
180     }
181 
182     public void typeKeys(String value)
183     {
184         client.typeKeys(getLocator(), value);
185     }
186 
187     public void typeWithFullKeyEvents(String value)
188     {
189         client.typeWithFullKeyEvents(getLocator(), value);
190     }
191 
192     public String getElementKey()
193     {
194         return key;
195     }
196 
197     public boolean isAutogeneratedKey()
198     {
199         return autogeneratedKey;
200     }
201 }