-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebElement.js
183 lines (161 loc) · 3.87 KB
/
WebElement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var
WebElement;
/**
* @constructor
*/
WebElement = function (elementId, wd) {
/**
* Get element ID for current session.
*
* @returns {String} Element ID.
*/
this.getElementId = function () {
return elementId;
};
/**
* Click on an element.
*
* @returns {*}
*/
this.click = function () {
wd.clickElement(this);
return this;
};
/**
* Submit a FORM element.
*
* The submit command may also be applied to any element that is a descendant of a FORM element.
*
* @returns {*}
*/
this.submit = function () {
wd.submitElement(this);
return this;
};
/**
* Returns the visible text for the element.
*
* @returns {String}
*/
this.getText = function () {
return wd.getElementText(this);
};
/**
* Send a sequence of key strokes to the active element. This command is similar to the WebDriver.type command in
* every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the
* state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are
* depressed.
*
* @param {String} value
*
* @returns {*}
*/
this.type = function (value) {
wd.type(this, value);
return this;
};
/**
* Query for an element's tag name.
*
* @returns {String}
*/
this.getTagName = function () {
return wd.getElementTagName(this);
};
/**
* Clear a TEXTAREA or text INPUT element's value.
*
* @returns {*}
*/
this.clear = function () {
wd.clear(this);
return this;
};
/**
* Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected.
*
* @returns {Boolean}
*/
this.isSelected = function () {
return wd.isSelected(this);
};
/**
* Determine if an element is currently enabled.
*
* @returns {Boolean}
*/
this.isEnabled = function () {
return wd.isEnabled(this);
};
/**
* Determine if an element is currently displayed.
*
* @returns {Boolean}
*/
this.isDisplayed = function () {
return wd.isDisplayed(this);
};
/**
* Get the value of an element's attribute.
*
* @param {String} name
*
* @returns {String}
*/
this.getAttribute = function (name) {
return wd.getAttribute(this, name);
};
/**
* Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page.
*
* @returns {x, y}
*/
this.getLocation = function () {
return wd.getLocation(this);
};
/**
* Determine an element's location on the screen once it has been scrolled into view.
*
* Note: This is considered an internal command and should only be used to determine an element's location for
* correctly generating native events.
*
* @returns {x, y} The X and Y coordinates for the element on the page.
*/
this.getLocationInView = function () {
return wd.getLocationInView(this);
};
/**
* Determine an element's size in pixels.
*
* @returns {width, height}
*/
this.getSize = function () {
return wd.getElementSize(this);
};
/**
* Query the value of an element's computed CSS property. The CSS property to query should be specified using the CSS
* property name, not the JavaScript property name (e.g. background-color instead of backgroundColor).
*
* @param {String} propertyName
*
* @returns {String}
*/
this.getCssProperty = function (propertyName) {
return wd.getCssProperty(this, propertyName);
};
/**
* Start dragging current element and drop it over the second element.
*
* @param {WebElement} element Second element.
*
* @returns {*}
*/
this.dragAndDropTo = function (element) {
wd.moveTo(this);
wd.buttonDown();
wd.moveTo(element);
wd.buttonUp();
return this;
};
};
module.exports = WebElement;