selenium-webdriver 0.0.29 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +15 -1
- data/lib/selenium-client.rb +2 -0
- data/lib/selenium/client.rb +30 -0
- data/lib/selenium/client/base.rb +118 -0
- data/lib/selenium/client/driver.rb +10 -0
- data/lib/selenium/client/errors.rb +9 -0
- data/lib/selenium/client/extensions.rb +118 -0
- data/lib/selenium/client/idiomatic.rb +488 -0
- data/lib/selenium/client/javascript_expression_builder.rb +116 -0
- data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
- data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
- data/lib/selenium/client/legacy_driver.rb +1711 -0
- data/lib/selenium/client/protocol.rb +104 -0
- data/lib/selenium/client/selenium_helper.rb +34 -0
- data/lib/selenium/rake/server_task.rb +131 -0
- data/lib/selenium/server.rb +114 -0
- data/lib/selenium/webdriver.rb +3 -2
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +45 -0
- data/lib/selenium/webdriver/chrome/extension.zip +0 -0
- data/lib/selenium/webdriver/chrome/launcher.rb +6 -3
- data/lib/selenium/webdriver/common.rb +2 -0
- data/lib/selenium/webdriver/common/driver.rb +8 -4
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +28 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +10 -0
- data/lib/selenium/webdriver/common/proxy.rb +119 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +27 -9
- data/lib/selenium/webdriver/firefox/binary.rb +8 -5
- data/lib/selenium/webdriver/firefox/bridge.rb +2 -3
- data/lib/selenium/webdriver/firefox/extension.rb +17 -14
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +8 -2
- data/lib/selenium/webdriver/firefox/profile.rb +45 -1
- data/lib/selenium/webdriver/firefox/socket_lock.rb +1 -5
- data/lib/selenium/webdriver/ie/bridge.rb +3 -3
- data/lib/selenium/webdriver/ie/native/win32/InternetExplorerDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/InternetExplorerDriver.dll +0 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +34 -0
- data/lib/selenium/webdriver/remote/bridge.rb +0 -1
- data/lib/selenium/webdriver/remote/capabilities.rb +46 -13
- data/lib/selenium/webdriver/remote/commands.rb +3 -4
- data/lib/selenium/webdriver/remote/http/common.rb +1 -1
- data/lib/selenium/webdriver/remote/http/default.rb +7 -1
- metadata +42 -7
@@ -0,0 +1,116 @@
|
|
1
|
+
module Selenium
|
2
|
+
module Client
|
3
|
+
|
4
|
+
class JavascriptExpressionBuilder
|
5
|
+
attr_reader :script
|
6
|
+
|
7
|
+
def initialize(javascript_framework_name=nil)
|
8
|
+
@framework = javascript_framework_for(javascript_framework_name) if javascript_framework_name
|
9
|
+
@script = ""
|
10
|
+
end
|
11
|
+
|
12
|
+
def append(text)
|
13
|
+
@script << text
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def no_pending_ajax_requests
|
18
|
+
append window_script("#{@framework.ajax_request_tracker} == 0")
|
19
|
+
end
|
20
|
+
|
21
|
+
def no_pending_effects
|
22
|
+
append window_script("Effect.Queue.size() == 0")
|
23
|
+
end
|
24
|
+
|
25
|
+
def visible(locator)
|
26
|
+
append "selenium.isVisible('#{quote_escaped(locator)}')"
|
27
|
+
end
|
28
|
+
|
29
|
+
def not_visible(locator)
|
30
|
+
append "!selenium.isVisible('#{quote_escaped(locator)}')"
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_element(locator)
|
34
|
+
append <<-EOS
|
35
|
+
var element;
|
36
|
+
|
37
|
+
try {
|
38
|
+
element = selenium.browserbot.findElement('#{quote_escaped(locator)}');
|
39
|
+
} catch(e) {
|
40
|
+
element = null;
|
41
|
+
}
|
42
|
+
EOS
|
43
|
+
end
|
44
|
+
|
45
|
+
def element_value_is(expected_value)
|
46
|
+
append "(element != null && element.value == '#{quote_escaped(expected_value)}')"
|
47
|
+
end
|
48
|
+
|
49
|
+
def element_value_is_not(expected_value)
|
50
|
+
append "(element == null || element.value != '#{quote_escaped(expected_value)}')"
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_text(pattern, options)
|
54
|
+
if options[:element].nil?
|
55
|
+
find_text_in_document pattern, options
|
56
|
+
else
|
57
|
+
find_text_in_element pattern, options
|
58
|
+
end
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def find_text_in_document(pattern, options)
|
64
|
+
js_regexp = case pattern
|
65
|
+
when Regexp
|
66
|
+
pattern.inspect
|
67
|
+
else
|
68
|
+
/#{pattern}/.inspect
|
69
|
+
end
|
70
|
+
append <<-EOS
|
71
|
+
var text_match;
|
72
|
+
text_match = (null != selenium.browserbot.getCurrentWindow().document.body.innerHTML.match(#{js_regexp}));
|
73
|
+
EOS
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_text_in_element(pattern, options)
|
78
|
+
find_element(options[:element])
|
79
|
+
append <<-EOS
|
80
|
+
var text_match;
|
81
|
+
text_match = (element != null && #{text_match(pattern)});
|
82
|
+
EOS
|
83
|
+
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def text_match(pattern)
|
88
|
+
case pattern
|
89
|
+
when Regexp
|
90
|
+
"null != element.innerHTML.match(#{pattern.inspect})"
|
91
|
+
else
|
92
|
+
"element.innerHTML == '#{quote_escaped(pattern)}'"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def javascript_framework_for(framework_name)
|
97
|
+
case framework_name.to_sym
|
98
|
+
when :prototype
|
99
|
+
JavascriptFrameworks::Prototype
|
100
|
+
when :jquery
|
101
|
+
JavascriptFrameworks::JQuery
|
102
|
+
else
|
103
|
+
raise "Unsupported Javascript Framework: #{framework_name}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def window_script(expression)
|
108
|
+
"selenium.browserbot.getCurrentWindow().#{expression};"
|
109
|
+
end
|
110
|
+
|
111
|
+
def quote_escaped(a_string)
|
112
|
+
a_string.gsub(/\\/, "\\\\\\").gsub(/'/, %q<\\\'>)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,1711 @@
|
|
1
|
+
|
2
|
+
# Copyright 2006 ThoughtWorks, Inc
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
# -----------------
|
18
|
+
# Original code by Aslak Hellesoy and Darren Hobbs
|
19
|
+
# This file has been automatically generated via XSL
|
20
|
+
# -----------------
|
21
|
+
|
22
|
+
# Defines an object that runs Selenium commands.
|
23
|
+
#
|
24
|
+
# ===Element Locators
|
25
|
+
# Element Locators tell Selenium which HTML element a command refers to.
|
26
|
+
# The format of a locator is:
|
27
|
+
# <em>locatorType</em><b>=</b><em>argument</em>
|
28
|
+
# We support the following strategies for locating elements:
|
29
|
+
#
|
30
|
+
# * <b>identifier</b>=<em>id</em>:
|
31
|
+
# Select the element with the specified @id attribute. If no match is
|
32
|
+
# found, select the first element whose @name attribute is <em>id</em>.
|
33
|
+
# (This is normally the default; see below.)
|
34
|
+
# * <b>id</b>=<em>id</em>:
|
35
|
+
# Select the element with the specified @id attribute.
|
36
|
+
# * <b>name</b>=<em>name</em>:
|
37
|
+
# Select the first element with the specified @name attribute.
|
38
|
+
# * username
|
39
|
+
# * name=username
|
40
|
+
#
|
41
|
+
# The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <b>value</b> is assumed.
|
42
|
+
# * name=flavour value=chocolate
|
43
|
+
#
|
44
|
+
#
|
45
|
+
# * <b>dom</b>=<em>javascriptExpression</em>:
|
46
|
+
#
|
47
|
+
# Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
|
48
|
+
# Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
|
49
|
+
# * dom=document.forms['myForm'].myDropdown
|
50
|
+
# * dom=document.images[56]
|
51
|
+
# * dom=function foo() { return document.links[1]; }; foo();
|
52
|
+
#
|
53
|
+
#
|
54
|
+
# * <b>xpath</b>=<em>xpathExpression</em>:
|
55
|
+
# Locate an element using an XPath expression.
|
56
|
+
# * xpath=//img[@alt='The image alt text']
|
57
|
+
# * xpath=//table[@id='table1']//tr[4]/td[2]
|
58
|
+
# * xpath=//a[contains(@href,'#id1')]
|
59
|
+
# * xpath=//a[contains(@href,'#id1')]/@class
|
60
|
+
# * xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
|
61
|
+
# * xpath=//input[@name='name2' and @value='yes']
|
62
|
+
# * xpath=//*[text()="right"]
|
63
|
+
#
|
64
|
+
#
|
65
|
+
# * <b>link</b>=<em>textPattern</em>:
|
66
|
+
# Select the link (anchor) element which contains text matching the
|
67
|
+
# specified <em>pattern</em>.
|
68
|
+
# * link=The link text
|
69
|
+
#
|
70
|
+
#
|
71
|
+
# * <b>css</b>=<em>cssSelectorSyntax</em>:
|
72
|
+
# Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
|
73
|
+
# * css=a[href="#id3"]
|
74
|
+
# * css=span#firstChild + span
|
75
|
+
#
|
76
|
+
# Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).
|
77
|
+
#
|
78
|
+
# * <b>ui</b>=<em>uiSpecifierString</em>:
|
79
|
+
# Locate an element by resolving the UI specifier string to another locator, and evaluating it. See the Selenium UI-Element Reference for more details.
|
80
|
+
# * ui=loginPages::loginButton()
|
81
|
+
# * ui=settingsPages::toggle(label=Hide Email)
|
82
|
+
# * ui=forumPages::postBody(index=2)//a[2]
|
83
|
+
#
|
84
|
+
#
|
85
|
+
#
|
86
|
+
#
|
87
|
+
# Without an explicit locator prefix, Selenium uses the following default
|
88
|
+
# strategies:
|
89
|
+
#
|
90
|
+
# * <b>dom</b>, for locators starting with "document."
|
91
|
+
# * <b>xpath</b>, for locators starting with "//"
|
92
|
+
# * <b>identifier</b>, otherwise
|
93
|
+
#
|
94
|
+
# ===Element FiltersElement filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.
|
95
|
+
# Filters look much like locators, ie.
|
96
|
+
# <em>filterType</em><b>=</b><em>argument</em>Supported element-filters are:
|
97
|
+
# <b>value=</b><em>valuePattern</em>
|
98
|
+
#
|
99
|
+
# Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.<b>index=</b><em>index</em>
|
100
|
+
#
|
101
|
+
# Selects a single element based on its position in the list (offset from zero).===String-match Patterns
|
102
|
+
# Various Pattern syntaxes are available for matching string values:
|
103
|
+
#
|
104
|
+
# * <b>glob:</b><em>pattern</em>:
|
105
|
+
# Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
|
106
|
+
# kind of limited regular-expression syntax typically used in command-line
|
107
|
+
# shells. In a glob pattern, "*" represents any sequence of characters, and "?"
|
108
|
+
# represents any single character. Glob patterns match against the entire
|
109
|
+
# string.
|
110
|
+
# * <b>regexp:</b><em>regexp</em>:
|
111
|
+
# Match a string using a regular-expression. The full power of JavaScript
|
112
|
+
# regular-expressions is available.
|
113
|
+
# * <b>regexpi:</b><em>regexpi</em>:
|
114
|
+
# Match a string using a case-insensitive regular-expression.
|
115
|
+
# * <b>exact:</b><em>string</em>:
|
116
|
+
#
|
117
|
+
# Match a string exactly, verbatim, without any of that fancy wildcard
|
118
|
+
# stuff.
|
119
|
+
#
|
120
|
+
#
|
121
|
+
# If no pattern prefix is specified, Selenium assumes that it's a "glob"
|
122
|
+
# pattern.
|
123
|
+
#
|
124
|
+
#
|
125
|
+
# For commands that return multiple values (such as verifySelectOptions),
|
126
|
+
# the string being matched is a comma-separated list of the return values,
|
127
|
+
# where both commas and backslashes in the values are backslash-escaped.
|
128
|
+
# When providing a pattern, the optional matching syntax (i.e. glob,
|
129
|
+
# regexp, etc.) is specified once, as usual, at the beginning of the
|
130
|
+
# pattern.
|
131
|
+
#
|
132
|
+
#
|
133
|
+
module Selenium
|
134
|
+
module Client
|
135
|
+
module GeneratedDriver
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
# Clicks on a link, button, checkbox or radio button. If the click action
|
140
|
+
# causes a new page to load (like a link usually does), call
|
141
|
+
# waitForPageToLoad.
|
142
|
+
#
|
143
|
+
# 'locator' is an element locator
|
144
|
+
def click(locator)
|
145
|
+
remote_control_command("click", [locator,])
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# Double clicks on a link, button, checkbox or radio button. If the double click action
|
150
|
+
# causes a new page to load (like a link usually does), call
|
151
|
+
# waitForPageToLoad.
|
152
|
+
#
|
153
|
+
# 'locator' is an element locator
|
154
|
+
def double_click(locator)
|
155
|
+
remote_control_command("doubleClick", [locator,])
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
# Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
|
160
|
+
#
|
161
|
+
# 'locator' is an element locator
|
162
|
+
def context_menu(locator)
|
163
|
+
remote_control_command("contextMenu", [locator,])
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
# Clicks on a link, button, checkbox or radio button. If the click action
|
168
|
+
# causes a new page to load (like a link usually does), call
|
169
|
+
# waitForPageToLoad.
|
170
|
+
#
|
171
|
+
# 'locator' is an element locator
|
172
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
173
|
+
def click_at(locator,coordString)
|
174
|
+
remote_control_command("clickAt", [locator,coordString,])
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# Doubleclicks on a link, button, checkbox or radio button. If the action
|
179
|
+
# causes a new page to load (like a link usually does), call
|
180
|
+
# waitForPageToLoad.
|
181
|
+
#
|
182
|
+
# 'locator' is an element locator
|
183
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
184
|
+
def double_click_at(locator,coordString)
|
185
|
+
remote_control_command("doubleClickAt", [locator,coordString,])
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
# Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
|
190
|
+
#
|
191
|
+
# 'locator' is an element locator
|
192
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
193
|
+
def context_menu_at(locator,coordString)
|
194
|
+
remote_control_command("contextMenuAt", [locator,coordString,])
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
# Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
|
199
|
+
# handler.
|
200
|
+
#
|
201
|
+
# 'locator' is an element locator
|
202
|
+
# 'eventName' is the event name, e.g. "focus" or "blur"
|
203
|
+
def fire_event(locator,eventName)
|
204
|
+
remote_control_command("fireEvent", [locator,eventName,])
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
# Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
|
209
|
+
#
|
210
|
+
# 'locator' is an element locator
|
211
|
+
def focus(locator)
|
212
|
+
remote_control_command("focus", [locator,])
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
# Simulates a user pressing and releasing a key.
|
217
|
+
#
|
218
|
+
# 'locator' is an element locator
|
219
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
220
|
+
def key_press(locator,keySequence)
|
221
|
+
remote_control_command("keyPress", [locator,keySequence,])
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
# Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
|
226
|
+
#
|
227
|
+
def shift_key_down()
|
228
|
+
remote_control_command("shiftKeyDown", [])
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
# Release the shift key.
|
233
|
+
#
|
234
|
+
def shift_key_up()
|
235
|
+
remote_control_command("shiftKeyUp", [])
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
# Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
|
240
|
+
#
|
241
|
+
def meta_key_down()
|
242
|
+
remote_control_command("metaKeyDown", [])
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
# Release the meta key.
|
247
|
+
#
|
248
|
+
def meta_key_up()
|
249
|
+
remote_control_command("metaKeyUp", [])
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
# Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
|
254
|
+
#
|
255
|
+
def alt_key_down()
|
256
|
+
remote_control_command("altKeyDown", [])
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
# Release the alt key.
|
261
|
+
#
|
262
|
+
def alt_key_up()
|
263
|
+
remote_control_command("altKeyUp", [])
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
# Press the control key and hold it down until doControlUp() is called or a new page is loaded.
|
268
|
+
#
|
269
|
+
def control_key_down()
|
270
|
+
remote_control_command("controlKeyDown", [])
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
# Release the control key.
|
275
|
+
#
|
276
|
+
def control_key_up()
|
277
|
+
remote_control_command("controlKeyUp", [])
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
# Simulates a user pressing a key (without releasing it yet).
|
282
|
+
#
|
283
|
+
# 'locator' is an element locator
|
284
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
285
|
+
def key_down(locator,keySequence)
|
286
|
+
remote_control_command("keyDown", [locator,keySequence,])
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
# Simulates a user releasing a key.
|
291
|
+
#
|
292
|
+
# 'locator' is an element locator
|
293
|
+
# 'keySequence' is Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
|
294
|
+
def key_up(locator,keySequence)
|
295
|
+
remote_control_command("keyUp", [locator,keySequence,])
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
# Simulates a user hovering a mouse over the specified element.
|
300
|
+
#
|
301
|
+
# 'locator' is an element locator
|
302
|
+
def mouse_over(locator)
|
303
|
+
remote_control_command("mouseOver", [locator,])
|
304
|
+
end
|
305
|
+
|
306
|
+
|
307
|
+
# Simulates a user moving the mouse pointer away from the specified element.
|
308
|
+
#
|
309
|
+
# 'locator' is an element locator
|
310
|
+
def mouse_out(locator)
|
311
|
+
remote_control_command("mouseOut", [locator,])
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
# Simulates a user pressing the left mouse button (without releasing it yet) on
|
316
|
+
# the specified element.
|
317
|
+
#
|
318
|
+
# 'locator' is an element locator
|
319
|
+
def mouse_down(locator)
|
320
|
+
remote_control_command("mouseDown", [locator,])
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
# Simulates a user pressing the right mouse button (without releasing it yet) on
|
325
|
+
# the specified element.
|
326
|
+
#
|
327
|
+
# 'locator' is an element locator
|
328
|
+
def mouse_down_right(locator)
|
329
|
+
remote_control_command("mouseDownRight", [locator,])
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
# Simulates a user pressing the left mouse button (without releasing it yet) at
|
334
|
+
# the specified location.
|
335
|
+
#
|
336
|
+
# 'locator' is an element locator
|
337
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
338
|
+
def mouse_down_at(locator,coordString)
|
339
|
+
remote_control_command("mouseDownAt", [locator,coordString,])
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
# Simulates a user pressing the right mouse button (without releasing it yet) at
|
344
|
+
# the specified location.
|
345
|
+
#
|
346
|
+
# 'locator' is an element locator
|
347
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
348
|
+
def mouse_down_right_at(locator,coordString)
|
349
|
+
remote_control_command("mouseDownRightAt", [locator,coordString,])
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
# Simulates the event that occurs when the user releases the mouse button (i.e., stops
|
354
|
+
# holding the button down) on the specified element.
|
355
|
+
#
|
356
|
+
# 'locator' is an element locator
|
357
|
+
def mouse_up(locator)
|
358
|
+
remote_control_command("mouseUp", [locator,])
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
# Simulates the event that occurs when the user releases the right mouse button (i.e., stops
|
363
|
+
# holding the button down) on the specified element.
|
364
|
+
#
|
365
|
+
# 'locator' is an element locator
|
366
|
+
def mouse_up_right(locator)
|
367
|
+
remote_control_command("mouseUpRight", [locator,])
|
368
|
+
end
|
369
|
+
|
370
|
+
|
371
|
+
# Simulates the event that occurs when the user releases the mouse button (i.e., stops
|
372
|
+
# holding the button down) at the specified location.
|
373
|
+
#
|
374
|
+
# 'locator' is an element locator
|
375
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
376
|
+
def mouse_up_at(locator,coordString)
|
377
|
+
remote_control_command("mouseUpAt", [locator,coordString,])
|
378
|
+
end
|
379
|
+
|
380
|
+
|
381
|
+
# Simulates the event that occurs when the user releases the right mouse button (i.e., stops
|
382
|
+
# holding the button down) at the specified location.
|
383
|
+
#
|
384
|
+
# 'locator' is an element locator
|
385
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
386
|
+
def mouse_up_right_at(locator,coordString)
|
387
|
+
remote_control_command("mouseUpRightAt", [locator,coordString,])
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
392
|
+
# the specified element.
|
393
|
+
#
|
394
|
+
# 'locator' is an element locator
|
395
|
+
def mouse_move(locator)
|
396
|
+
remote_control_command("mouseMove", [locator,])
|
397
|
+
end
|
398
|
+
|
399
|
+
|
400
|
+
# Simulates a user pressing the mouse button (without releasing it yet) on
|
401
|
+
# the specified element.
|
402
|
+
#
|
403
|
+
# 'locator' is an element locator
|
404
|
+
# 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
|
405
|
+
def mouse_move_at(locator,coordString)
|
406
|
+
remote_control_command("mouseMoveAt", [locator,coordString,])
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
# Sets the value of an input field, as though you typed it in.
|
411
|
+
#
|
412
|
+
# Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
|
413
|
+
# value should be the value of the option selected, not the visible text.
|
414
|
+
#
|
415
|
+
#
|
416
|
+
# 'locator' is an element locator
|
417
|
+
# 'value' is the value to type
|
418
|
+
def type(locator,value)
|
419
|
+
remote_control_command("type", [locator,value,])
|
420
|
+
end
|
421
|
+
|
422
|
+
|
423
|
+
# Simulates keystroke events on the specified element, as though you typed the value key-by-key.
|
424
|
+
#
|
425
|
+
# This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;
|
426
|
+
# this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
|
427
|
+
# Unlike the simple "type" command, which forces the specified value into the page directly, this command
|
428
|
+
# may or may not have any visible effect, even in cases where typing keys would normally have a visible effect.
|
429
|
+
# For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in
|
430
|
+
# the field.
|
431
|
+
# In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to
|
432
|
+
# send the keystroke events corresponding to what you just typed.
|
433
|
+
#
|
434
|
+
#
|
435
|
+
# 'locator' is an element locator
|
436
|
+
# 'value' is the value to type
|
437
|
+
def type_keys(locator,value)
|
438
|
+
remote_control_command("typeKeys", [locator,value,])
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
# Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e.,
|
443
|
+
# the delay is 0 milliseconds.
|
444
|
+
#
|
445
|
+
# 'value' is the number of milliseconds to pause after operation
|
446
|
+
def set_speed(value)
|
447
|
+
remote_control_command("setSpeed", [value,])
|
448
|
+
end
|
449
|
+
|
450
|
+
|
451
|
+
# Get execution speed (i.e., get the millisecond length of the delay following each selenium operation). By default, there is no such delay, i.e.,
|
452
|
+
# the delay is 0 milliseconds.
|
453
|
+
#
|
454
|
+
# See also setSpeed.
|
455
|
+
#
|
456
|
+
def get_speed()
|
457
|
+
return string_command("getSpeed", [])
|
458
|
+
end
|
459
|
+
|
460
|
+
|
461
|
+
# Check a toggle-button (checkbox/radio)
|
462
|
+
#
|
463
|
+
# 'locator' is an element locator
|
464
|
+
def check(locator)
|
465
|
+
remote_control_command("check", [locator,])
|
466
|
+
end
|
467
|
+
|
468
|
+
|
469
|
+
# Uncheck a toggle-button (checkbox/radio)
|
470
|
+
#
|
471
|
+
# 'locator' is an element locator
|
472
|
+
def uncheck(locator)
|
473
|
+
remote_control_command("uncheck", [locator,])
|
474
|
+
end
|
475
|
+
|
476
|
+
|
477
|
+
# Select an option from a drop-down using an option locator.
|
478
|
+
#
|
479
|
+
#
|
480
|
+
# Option locators provide different ways of specifying options of an HTML
|
481
|
+
# Select element (e.g. for selecting a specific option, or for asserting
|
482
|
+
# that the selected option satisfies a specification). There are several
|
483
|
+
# forms of Select Option Locator.
|
484
|
+
#
|
485
|
+
# * <b>label</b>=<em>labelPattern</em>:
|
486
|
+
# matches options based on their labels, i.e. the visible text. (This
|
487
|
+
# is the default.)
|
488
|
+
# * label=regexp:^[Oo]ther
|
489
|
+
#
|
490
|
+
#
|
491
|
+
# * <b>value</b>=<em>valuePattern</em>:
|
492
|
+
# matches options based on their values.
|
493
|
+
# * value=other
|
494
|
+
#
|
495
|
+
#
|
496
|
+
# * <b>id</b>=<em>id</em>:
|
497
|
+
#
|
498
|
+
# matches options based on their ids.
|
499
|
+
# * id=option1
|
500
|
+
#
|
501
|
+
#
|
502
|
+
# * <b>index</b>=<em>index</em>:
|
503
|
+
# matches an option based on its index (offset from zero).
|
504
|
+
# * index=2
|
505
|
+
#
|
506
|
+
#
|
507
|
+
#
|
508
|
+
#
|
509
|
+
# If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
|
510
|
+
#
|
511
|
+
#
|
512
|
+
#
|
513
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
514
|
+
# 'optionLocator' is an option locator (a label by default)
|
515
|
+
def select(selectLocator,optionLocator)
|
516
|
+
remote_control_command("select", [selectLocator,optionLocator,])
|
517
|
+
end
|
518
|
+
|
519
|
+
|
520
|
+
# Add a selection to the set of selected options in a multi-select element using an option locator.
|
521
|
+
#
|
522
|
+
# @see #doSelect for details of option locators
|
523
|
+
#
|
524
|
+
# 'locator' is an element locator identifying a multi-select box
|
525
|
+
# 'optionLocator' is an option locator (a label by default)
|
526
|
+
def add_selection(locator,optionLocator)
|
527
|
+
remote_control_command("addSelection", [locator,optionLocator,])
|
528
|
+
end
|
529
|
+
|
530
|
+
|
531
|
+
# Remove a selection from the set of selected options in a multi-select element using an option locator.
|
532
|
+
#
|
533
|
+
# @see #doSelect for details of option locators
|
534
|
+
#
|
535
|
+
# 'locator' is an element locator identifying a multi-select box
|
536
|
+
# 'optionLocator' is an option locator (a label by default)
|
537
|
+
def remove_selection(locator,optionLocator)
|
538
|
+
remote_control_command("removeSelection", [locator,optionLocator,])
|
539
|
+
end
|
540
|
+
|
541
|
+
|
542
|
+
# Unselects all of the selected options in a multi-select element.
|
543
|
+
#
|
544
|
+
# 'locator' is an element locator identifying a multi-select box
|
545
|
+
def remove_all_selections(locator)
|
546
|
+
remote_control_command("removeAllSelections", [locator,])
|
547
|
+
end
|
548
|
+
|
549
|
+
|
550
|
+
# Submit the specified form. This is particularly useful for forms without
|
551
|
+
# submit buttons, e.g. single-input "Search" forms.
|
552
|
+
#
|
553
|
+
# 'formLocator' is an element locator for the form you want to submit
|
554
|
+
def submit(formLocator)
|
555
|
+
remote_control_command("submit", [formLocator,])
|
556
|
+
end
|
557
|
+
|
558
|
+
|
559
|
+
# Opens an URL in the test frame. This accepts both relative and absolute
|
560
|
+
# URLs.
|
561
|
+
#
|
562
|
+
# The "open" command waits for the page to load before proceeding,
|
563
|
+
# ie. the "AndWait" suffix is implicit.
|
564
|
+
#
|
565
|
+
# <em>Note</em>: The URL must be on the same domain as the runner HTML
|
566
|
+
# due to security restrictions in the browser (Same Origin Policy). If you
|
567
|
+
# need to open an URL on another domain, use the Selenium Server to start a
|
568
|
+
# new browser session on that domain.
|
569
|
+
#
|
570
|
+
# 'url' is the URL to open; may be relative or absolute
|
571
|
+
def open(url)
|
572
|
+
remote_control_command("open", [url,])
|
573
|
+
end
|
574
|
+
|
575
|
+
|
576
|
+
# Opens a popup window (if a window with that ID isn't already open).
|
577
|
+
# After opening the window, you'll need to select it using the selectWindow
|
578
|
+
# command.
|
579
|
+
#
|
580
|
+
# This command can also be a useful workaround for bug SEL-339. In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
|
581
|
+
# In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
|
582
|
+
# an empty (blank) url, like this: openWindow("", "myFunnyWindow").
|
583
|
+
#
|
584
|
+
#
|
585
|
+
# 'url' is the URL to open, which can be blank
|
586
|
+
# 'windowID' is the JavaScript window ID of the window to select
|
587
|
+
def open_window(url,windowID)
|
588
|
+
remote_control_command("openWindow", [url,windowID,])
|
589
|
+
end
|
590
|
+
|
591
|
+
|
592
|
+
# Selects a popup window using a window locator; once a popup window has been selected, all
|
593
|
+
# commands go to that window. To select the main window again, use null
|
594
|
+
# as the target.
|
595
|
+
#
|
596
|
+
#
|
597
|
+
#
|
598
|
+
# Window locators provide different ways of specifying the window object:
|
599
|
+
# by title, by internal JavaScript "name," or by JavaScript variable.
|
600
|
+
#
|
601
|
+
# * <b>title</b>=<em>My Special Window</em>:
|
602
|
+
# Finds the window using the text that appears in the title bar. Be careful;
|
603
|
+
# two windows can share the same title. If that happens, this locator will
|
604
|
+
# just pick one.
|
605
|
+
#
|
606
|
+
# * <b>name</b>=<em>myWindow</em>:
|
607
|
+
# Finds the window using its internal JavaScript "name" property. This is the second
|
608
|
+
# parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
|
609
|
+
# (which Selenium intercepts).
|
610
|
+
#
|
611
|
+
# * <b>var</b>=<em>variableName</em>:
|
612
|
+
# Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current
|
613
|
+
# application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using
|
614
|
+
# "var=foo".
|
615
|
+
#
|
616
|
+
#
|
617
|
+
#
|
618
|
+
# If no window locator prefix is provided, we'll try to guess what you mean like this:
|
619
|
+
# 1.) if windowID is null, (or the string "null") then it is assumed the user is referring to the original window instantiated by the browser).
|
620
|
+
# 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
|
621
|
+
# that this variable contains the return value from a call to the JavaScript window.open() method.
|
622
|
+
# 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".
|
623
|
+
# 4.) If <em>that</em> fails, we'll try looping over all of the known windows to try to find the appropriate "title".
|
624
|
+
# Since "title" is not necessarily unique, this may have unexpected behavior.
|
625
|
+
# If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messages
|
626
|
+
# which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages
|
627
|
+
# like the following for each window as it is opened:
|
628
|
+
# <tt>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</tt>
|
629
|
+
# In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
|
630
|
+
# (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
|
631
|
+
# an empty (blank) url, like this: openWindow("", "myFunnyWindow").
|
632
|
+
#
|
633
|
+
#
|
634
|
+
# 'windowID' is the JavaScript window ID of the window to select
|
635
|
+
def select_window(windowID)
|
636
|
+
remote_control_command("selectWindow", [windowID,])
|
637
|
+
end
|
638
|
+
|
639
|
+
|
640
|
+
# Simplifies the process of selecting a popup window (and does not offer
|
641
|
+
# functionality beyond what <tt>selectWindow()</tt> already provides).
|
642
|
+
# * If <tt>windowID</tt> is either not specified, or specified as
|
643
|
+
# "null", the first non-top window is selected. The top window is the one
|
644
|
+
# that would be selected by <tt>selectWindow()</tt> without providing a
|
645
|
+
# <tt>windowID</tt> . This should not be used when more than one popup
|
646
|
+
# window is in play.
|
647
|
+
# * Otherwise, the window will be looked up considering
|
648
|
+
# <tt>windowID</tt> as the following in order: 1) the "name" of the
|
649
|
+
# window, as specified to <tt>window.open()</tt>; 2) a javascript
|
650
|
+
# variable which is a reference to a window; and 3) the title of the
|
651
|
+
# window. This is the same ordered lookup performed by
|
652
|
+
# <tt>selectWindow</tt> .
|
653
|
+
#
|
654
|
+
#
|
655
|
+
#
|
656
|
+
# 'windowID' is an identifier for the popup window, which can take on a number of different meanings
|
657
|
+
def select_pop_up(windowID)
|
658
|
+
remote_control_command("selectPopUp", [windowID,])
|
659
|
+
end
|
660
|
+
|
661
|
+
|
662
|
+
# Selects the main window. Functionally equivalent to using
|
663
|
+
# <tt>selectWindow()</tt> and specifying no value for
|
664
|
+
# <tt>windowID</tt>.
|
665
|
+
#
|
666
|
+
def deselect_pop_up()
|
667
|
+
remote_control_command("deselectPopUp", [])
|
668
|
+
end
|
669
|
+
|
670
|
+
|
671
|
+
# Selects a frame within the current window. (You may invoke this command
|
672
|
+
# multiple times to select nested frames.) To select the parent frame, use
|
673
|
+
# "relative=parent" as a locator; to select the top frame, use "relative=top".
|
674
|
+
# You can also select a frame by its 0-based index number; select the first frame with
|
675
|
+
# "index=0", or the third frame with "index=2".
|
676
|
+
#
|
677
|
+
# You may also use a DOM expression to identify the frame you want directly,
|
678
|
+
# like this: <tt>dom=frames["main"].frames["subframe"]</tt>
|
679
|
+
#
|
680
|
+
#
|
681
|
+
# 'locator' is an element locator identifying a frame or iframe
|
682
|
+
def select_frame(locator)
|
683
|
+
remote_control_command("selectFrame", [locator,])
|
684
|
+
end
|
685
|
+
|
686
|
+
|
687
|
+
# Determine whether current/locator identify the frame containing this running code.
|
688
|
+
#
|
689
|
+
# This is useful in proxy injection mode, where this code runs in every
|
690
|
+
# browser frame and window, and sometimes the selenium server needs to identify
|
691
|
+
# the "current" frame. In this case, when the test calls selectFrame, this
|
692
|
+
# routine is called for each frame to figure out which one has been selected.
|
693
|
+
# The selected frame will return true, while all others will return false.
|
694
|
+
#
|
695
|
+
#
|
696
|
+
# 'currentFrameString' is starting frame
|
697
|
+
# 'target' is new frame (which might be relative to the current one)
|
698
|
+
def get_whether_this_frame_match_frame_expression(currentFrameString,target)
|
699
|
+
return boolean_command("getWhetherThisFrameMatchFrameExpression", [currentFrameString,target,])
|
700
|
+
end
|
701
|
+
|
702
|
+
|
703
|
+
# Determine whether currentWindowString plus target identify the window containing this running code.
|
704
|
+
#
|
705
|
+
# This is useful in proxy injection mode, where this code runs in every
|
706
|
+
# browser frame and window, and sometimes the selenium server needs to identify
|
707
|
+
# the "current" window. In this case, when the test calls selectWindow, this
|
708
|
+
# routine is called for each window to figure out which one has been selected.
|
709
|
+
# The selected window will return true, while all others will return false.
|
710
|
+
#
|
711
|
+
#
|
712
|
+
# 'currentWindowString' is starting window
|
713
|
+
# 'target' is new window (which might be relative to the current one, e.g., "_parent")
|
714
|
+
def get_whether_this_window_match_window_expression(currentWindowString,target)
|
715
|
+
return boolean_command("getWhetherThisWindowMatchWindowExpression", [currentWindowString,target,])
|
716
|
+
end
|
717
|
+
|
718
|
+
|
719
|
+
# Waits for a popup window to appear and load up.
|
720
|
+
#
|
721
|
+
# 'windowID' is the JavaScript window "name" of the window that will appear (not the text of the title bar) If unspecified, or specified as "null", this command will wait for the first non-top window to appear (don't rely on this if you are working with multiple popups simultaneously).
|
722
|
+
# 'timeout' is a timeout in milliseconds, after which the action will return with an error. If this value is not specified, the default Selenium timeout will be used. See the setTimeout() command.
|
723
|
+
def wait_for_pop_up(windowID,timeout)
|
724
|
+
remote_control_command("waitForPopUp", [windowID,timeout,])
|
725
|
+
end
|
726
|
+
|
727
|
+
|
728
|
+
#
|
729
|
+
# By default, Selenium's overridden window.confirm() function will
|
730
|
+
# return true, as if the user had manually clicked OK; after running
|
731
|
+
# this command, the next call to confirm() will return false, as if
|
732
|
+
# the user had clicked Cancel. Selenium will then resume using the
|
733
|
+
# default behavior for future confirmations, automatically returning
|
734
|
+
# true (OK) unless/until you explicitly call this command for each
|
735
|
+
# confirmation.
|
736
|
+
#
|
737
|
+
#
|
738
|
+
# Take note - every time a confirmation comes up, you must
|
739
|
+
# consume it with a corresponding getConfirmation, or else
|
740
|
+
# the next selenium operation will fail.
|
741
|
+
#
|
742
|
+
#
|
743
|
+
#
|
744
|
+
def choose_cancel_on_next_confirmation()
|
745
|
+
remote_control_command("chooseCancelOnNextConfirmation", [])
|
746
|
+
end
|
747
|
+
|
748
|
+
|
749
|
+
#
|
750
|
+
# Undo the effect of calling chooseCancelOnNextConfirmation. Note
|
751
|
+
# that Selenium's overridden window.confirm() function will normally automatically
|
752
|
+
# return true, as if the user had manually clicked OK, so you shouldn't
|
753
|
+
# need to use this command unless for some reason you need to change
|
754
|
+
# your mind prior to the next confirmation. After any confirmation, Selenium will resume using the
|
755
|
+
# default behavior for future confirmations, automatically returning
|
756
|
+
# true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each
|
757
|
+
# confirmation.
|
758
|
+
#
|
759
|
+
#
|
760
|
+
# Take note - every time a confirmation comes up, you must
|
761
|
+
# consume it with a corresponding getConfirmation, or else
|
762
|
+
# the next selenium operation will fail.
|
763
|
+
#
|
764
|
+
#
|
765
|
+
#
|
766
|
+
def choose_ok_on_next_confirmation()
|
767
|
+
remote_control_command("chooseOkOnNextConfirmation", [])
|
768
|
+
end
|
769
|
+
|
770
|
+
|
771
|
+
# Instructs Selenium to return the specified answer string in response to
|
772
|
+
# the next JavaScript prompt [window.prompt()].
|
773
|
+
#
|
774
|
+
# 'answer' is the answer to give in response to the prompt pop-up
|
775
|
+
def answer_on_next_prompt(answer)
|
776
|
+
remote_control_command("answerOnNextPrompt", [answer,])
|
777
|
+
end
|
778
|
+
|
779
|
+
|
780
|
+
# Simulates the user clicking the "back" button on their browser.
|
781
|
+
#
|
782
|
+
def go_back()
|
783
|
+
remote_control_command("goBack", [])
|
784
|
+
end
|
785
|
+
|
786
|
+
|
787
|
+
# Simulates the user clicking the "Refresh" button on their browser.
|
788
|
+
#
|
789
|
+
def refresh()
|
790
|
+
remote_control_command("refresh", [])
|
791
|
+
end
|
792
|
+
|
793
|
+
|
794
|
+
# Simulates the user clicking the "close" button in the titlebar of a popup
|
795
|
+
# window or tab.
|
796
|
+
#
|
797
|
+
def close()
|
798
|
+
remote_control_command("close", [])
|
799
|
+
end
|
800
|
+
|
801
|
+
|
802
|
+
# Has an alert occurred?
|
803
|
+
#
|
804
|
+
#
|
805
|
+
# This function never throws an exception
|
806
|
+
#
|
807
|
+
#
|
808
|
+
#
|
809
|
+
def is_alert_present()
|
810
|
+
return boolean_command("isAlertPresent", [])
|
811
|
+
end
|
812
|
+
|
813
|
+
|
814
|
+
# Has a prompt occurred?
|
815
|
+
#
|
816
|
+
#
|
817
|
+
# This function never throws an exception
|
818
|
+
#
|
819
|
+
#
|
820
|
+
#
|
821
|
+
def is_prompt_present()
|
822
|
+
return boolean_command("isPromptPresent", [])
|
823
|
+
end
|
824
|
+
|
825
|
+
|
826
|
+
# Has confirm() been called?
|
827
|
+
#
|
828
|
+
#
|
829
|
+
# This function never throws an exception
|
830
|
+
#
|
831
|
+
#
|
832
|
+
#
|
833
|
+
def is_confirmation_present()
|
834
|
+
return boolean_command("isConfirmationPresent", [])
|
835
|
+
end
|
836
|
+
|
837
|
+
|
838
|
+
# Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
|
839
|
+
#
|
840
|
+
# Getting an alert has the same effect as manually clicking OK. If an
|
841
|
+
# alert is generated but you do not consume it with getAlert, the next Selenium action
|
842
|
+
# will fail.
|
843
|
+
# Under Selenium, JavaScript alerts will NOT pop up a visible alert
|
844
|
+
# dialog.
|
845
|
+
# Selenium does NOT support JavaScript alerts that are generated in a
|
846
|
+
# page's onload() event handler. In this case a visible dialog WILL be
|
847
|
+
# generated and Selenium will hang until someone manually clicks OK.
|
848
|
+
#
|
849
|
+
#
|
850
|
+
def get_alert()
|
851
|
+
return string_command("getAlert", [])
|
852
|
+
end
|
853
|
+
|
854
|
+
|
855
|
+
# Retrieves the message of a JavaScript confirmation dialog generated during
|
856
|
+
# the previous action.
|
857
|
+
#
|
858
|
+
#
|
859
|
+
# By default, the confirm function will return true, having the same effect
|
860
|
+
# as manually clicking OK. This can be changed by prior execution of the
|
861
|
+
# chooseCancelOnNextConfirmation command.
|
862
|
+
#
|
863
|
+
#
|
864
|
+
# If an confirmation is generated but you do not consume it with getConfirmation,
|
865
|
+
# the next Selenium action will fail.
|
866
|
+
#
|
867
|
+
#
|
868
|
+
# NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
|
869
|
+
# dialog.
|
870
|
+
#
|
871
|
+
#
|
872
|
+
# NOTE: Selenium does NOT support JavaScript confirmations that are
|
873
|
+
# generated in a page's onload() event handler. In this case a visible
|
874
|
+
# dialog WILL be generated and Selenium will hang until you manually click
|
875
|
+
# OK.
|
876
|
+
#
|
877
|
+
#
|
878
|
+
#
|
879
|
+
def get_confirmation()
|
880
|
+
return string_command("getConfirmation", [])
|
881
|
+
end
|
882
|
+
|
883
|
+
|
884
|
+
# Retrieves the message of a JavaScript question prompt dialog generated during
|
885
|
+
# the previous action.
|
886
|
+
#
|
887
|
+
# Successful handling of the prompt requires prior execution of the
|
888
|
+
# answerOnNextPrompt command. If a prompt is generated but you
|
889
|
+
# do not get/verify it, the next Selenium action will fail.
|
890
|
+
# NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
|
891
|
+
# dialog.
|
892
|
+
# NOTE: Selenium does NOT support JavaScript prompts that are generated in a
|
893
|
+
# page's onload() event handler. In this case a visible dialog WILL be
|
894
|
+
# generated and Selenium will hang until someone manually clicks OK.
|
895
|
+
#
|
896
|
+
#
|
897
|
+
def get_prompt()
|
898
|
+
return string_command("getPrompt", [])
|
899
|
+
end
|
900
|
+
|
901
|
+
|
902
|
+
# Gets the absolute URL of the current page.
|
903
|
+
#
|
904
|
+
def get_location()
|
905
|
+
return string_command("getLocation", [])
|
906
|
+
end
|
907
|
+
|
908
|
+
|
909
|
+
# Gets the title of the current page.
|
910
|
+
#
|
911
|
+
def get_title()
|
912
|
+
return string_command("getTitle", [])
|
913
|
+
end
|
914
|
+
|
915
|
+
|
916
|
+
# Gets the entire text of the page.
|
917
|
+
#
|
918
|
+
def get_body_text()
|
919
|
+
return string_command("getBodyText", [])
|
920
|
+
end
|
921
|
+
|
922
|
+
|
923
|
+
# Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
|
924
|
+
# For checkbox/radio elements, the value will be "on" or "off" depending on
|
925
|
+
# whether the element is checked or not.
|
926
|
+
#
|
927
|
+
# 'locator' is an element locator
|
928
|
+
def get_value(locator)
|
929
|
+
return string_command("getValue", [locator,])
|
930
|
+
end
|
931
|
+
|
932
|
+
|
933
|
+
# Gets the text of an element. This works for any element that contains
|
934
|
+
# text. This command uses either the textContent (Mozilla-like browsers) or
|
935
|
+
# the innerText (IE-like browsers) of the element, which is the rendered
|
936
|
+
# text shown to the user.
|
937
|
+
#
|
938
|
+
# 'locator' is an element locator
|
939
|
+
def get_text(locator)
|
940
|
+
return string_command("getText", [locator,])
|
941
|
+
end
|
942
|
+
|
943
|
+
|
944
|
+
# Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
|
945
|
+
#
|
946
|
+
# 'locator' is an element locator
|
947
|
+
def highlight(locator)
|
948
|
+
remote_control_command("highlight", [locator,])
|
949
|
+
end
|
950
|
+
|
951
|
+
|
952
|
+
# Gets the result of evaluating the specified JavaScript snippet. The snippet may
|
953
|
+
# have multiple lines, but only the result of the last line will be returned.
|
954
|
+
#
|
955
|
+
# Note that, by default, the snippet will run in the context of the "selenium"
|
956
|
+
# object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
|
957
|
+
# refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
|
958
|
+
# If you need to use
|
959
|
+
# a locator to refer to a single element in your application page, you can
|
960
|
+
# use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
|
961
|
+
#
|
962
|
+
#
|
963
|
+
# 'script' is the JavaScript snippet to run
|
964
|
+
def get_eval(script)
|
965
|
+
return string_command("getEval", [script,])
|
966
|
+
end
|
967
|
+
|
968
|
+
|
969
|
+
# Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
|
970
|
+
#
|
971
|
+
# 'locator' is an element locator pointing to a checkbox or radio button
|
972
|
+
def is_checked(locator)
|
973
|
+
return boolean_command("isChecked", [locator,])
|
974
|
+
end
|
975
|
+
|
976
|
+
|
977
|
+
# Gets the text from a cell of a table. The cellAddress syntax
|
978
|
+
# tableLocator.row.column, where row and column start at 0.
|
979
|
+
#
|
980
|
+
# 'tableCellAddress' is a cell address, e.g. "foo.1.4"
|
981
|
+
def get_table(tableCellAddress)
|
982
|
+
return string_command("getTable", [tableCellAddress,])
|
983
|
+
end
|
984
|
+
|
985
|
+
|
986
|
+
# Gets all option labels (visible text) for selected options in the specified select or multi-select element.
|
987
|
+
#
|
988
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
989
|
+
def get_selected_labels(selectLocator)
|
990
|
+
return string_array_command("getSelectedLabels", [selectLocator,])
|
991
|
+
end
|
992
|
+
|
993
|
+
|
994
|
+
# Gets option label (visible text) for selected option in the specified select element.
|
995
|
+
#
|
996
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
997
|
+
def get_selected_label(selectLocator)
|
998
|
+
return string_command("getSelectedLabel", [selectLocator,])
|
999
|
+
end
|
1000
|
+
|
1001
|
+
|
1002
|
+
# Gets all option values (value attributes) for selected options in the specified select or multi-select element.
|
1003
|
+
#
|
1004
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1005
|
+
def get_selected_values(selectLocator)
|
1006
|
+
return string_array_command("getSelectedValues", [selectLocator,])
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
|
1010
|
+
# Gets option value (value attribute) for selected option in the specified select element.
|
1011
|
+
#
|
1012
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1013
|
+
def get_selected_value(selectLocator)
|
1014
|
+
return string_command("getSelectedValue", [selectLocator,])
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
|
1018
|
+
# Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
|
1019
|
+
#
|
1020
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1021
|
+
def get_selected_indexes(selectLocator)
|
1022
|
+
return string_array_command("getSelectedIndexes", [selectLocator,])
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
|
1026
|
+
# Gets option index (option number, starting at 0) for selected option in the specified select element.
|
1027
|
+
#
|
1028
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1029
|
+
def get_selected_index(selectLocator)
|
1030
|
+
return string_command("getSelectedIndex", [selectLocator,])
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
|
1034
|
+
# Gets all option element IDs for selected options in the specified select or multi-select element.
|
1035
|
+
#
|
1036
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1037
|
+
def get_selected_ids(selectLocator)
|
1038
|
+
return string_array_command("getSelectedIds", [selectLocator,])
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
|
1042
|
+
# Gets option element ID for selected option in the specified select element.
|
1043
|
+
#
|
1044
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1045
|
+
def get_selected_id(selectLocator)
|
1046
|
+
return string_command("getSelectedId", [selectLocator,])
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
|
1050
|
+
# Determines whether some option in a drop-down menu is selected.
|
1051
|
+
#
|
1052
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1053
|
+
def is_something_selected(selectLocator)
|
1054
|
+
return boolean_command("isSomethingSelected", [selectLocator,])
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
|
1058
|
+
# Gets all option labels in the specified select drop-down.
|
1059
|
+
#
|
1060
|
+
# 'selectLocator' is an element locator identifying a drop-down menu
|
1061
|
+
def get_select_options(selectLocator)
|
1062
|
+
return string_array_command("getSelectOptions", [selectLocator,])
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
|
1066
|
+
# Gets the value of an element attribute. The value of the attribute may
|
1067
|
+
# differ across browsers (this is the case for the "style" attribute, for
|
1068
|
+
# example).
|
1069
|
+
#
|
1070
|
+
# 'attributeLocator' is an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"
|
1071
|
+
def get_attribute(attributeLocator)
|
1072
|
+
return string_command("getAttribute", [attributeLocator,])
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
|
1076
|
+
# Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
|
1077
|
+
#
|
1078
|
+
# 'pattern' is a pattern to match with the text of the page
|
1079
|
+
def is_text_present(pattern)
|
1080
|
+
return boolean_command("isTextPresent", [pattern,])
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
|
1084
|
+
# Verifies that the specified element is somewhere on the page.
|
1085
|
+
#
|
1086
|
+
# 'locator' is an element locator
|
1087
|
+
def is_element_present(locator)
|
1088
|
+
return boolean_command("isElementPresent", [locator,])
|
1089
|
+
end
|
1090
|
+
|
1091
|
+
|
1092
|
+
# Determines if the specified element is visible. An
|
1093
|
+
# element can be rendered invisible by setting the CSS "visibility"
|
1094
|
+
# property to "hidden", or the "display" property to "none", either for the
|
1095
|
+
# element itself or one if its ancestors. This method will fail if
|
1096
|
+
# the element is not present.
|
1097
|
+
#
|
1098
|
+
# 'locator' is an element locator
|
1099
|
+
def is_visible(locator)
|
1100
|
+
return boolean_command("isVisible", [locator,])
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
|
1104
|
+
# Determines whether the specified input element is editable, ie hasn't been disabled.
|
1105
|
+
# This method will fail if the specified element isn't an input element.
|
1106
|
+
#
|
1107
|
+
# 'locator' is an element locator
|
1108
|
+
def is_editable(locator)
|
1109
|
+
return boolean_command("isEditable", [locator,])
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
|
1113
|
+
# Returns the IDs of all buttons on the page.
|
1114
|
+
#
|
1115
|
+
# If a given button has no ID, it will appear as "" in this array.
|
1116
|
+
#
|
1117
|
+
#
|
1118
|
+
def get_all_buttons()
|
1119
|
+
return string_array_command("getAllButtons", [])
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
|
1123
|
+
# Returns the IDs of all links on the page.
|
1124
|
+
#
|
1125
|
+
# If a given link has no ID, it will appear as "" in this array.
|
1126
|
+
#
|
1127
|
+
#
|
1128
|
+
def get_all_links()
|
1129
|
+
return string_array_command("getAllLinks", [])
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
|
1133
|
+
# Returns the IDs of all input fields on the page.
|
1134
|
+
#
|
1135
|
+
# If a given field has no ID, it will appear as "" in this array.
|
1136
|
+
#
|
1137
|
+
#
|
1138
|
+
def get_all_fields()
|
1139
|
+
return string_array_command("getAllFields", [])
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
|
1143
|
+
# Returns an array of JavaScript property values from all known windows having one.
|
1144
|
+
#
|
1145
|
+
# 'attributeName' is name of an attribute on the windows
|
1146
|
+
def get_attribute_from_all_windows(attributeName)
|
1147
|
+
return string_array_command("getAttributeFromAllWindows", [attributeName,])
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
|
1151
|
+
# deprecated - use dragAndDrop instead
|
1152
|
+
#
|
1153
|
+
# 'locator' is an element locator
|
1154
|
+
# 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
|
1155
|
+
def dragdrop(locator,movementsString)
|
1156
|
+
remote_control_command("dragdrop", [locator,movementsString,])
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
|
1160
|
+
# Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
|
1161
|
+
# Setting this value to 0 means that we'll send a "mousemove" event to every single pixel
|
1162
|
+
# in between the start location and the end location; that can be very slow, and may
|
1163
|
+
# cause some browsers to force the JavaScript to timeout.
|
1164
|
+
# If the mouse speed is greater than the distance between the two dragged objects, we'll
|
1165
|
+
# just send one "mousemove" at the start location and then one final one at the end location.
|
1166
|
+
#
|
1167
|
+
#
|
1168
|
+
# 'pixels' is the number of pixels between "mousemove" events
|
1169
|
+
def set_mouse_speed(pixels)
|
1170
|
+
remote_control_command("setMouseSpeed", [pixels,])
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
|
1174
|
+
# Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
|
1175
|
+
#
|
1176
|
+
def get_mouse_speed()
|
1177
|
+
return number_command("getMouseSpeed", [])
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
|
1181
|
+
# Drags an element a certain distance and then drops it
|
1182
|
+
#
|
1183
|
+
# 'locator' is an element locator
|
1184
|
+
# 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
|
1185
|
+
def drag_and_drop(locator,movementsString)
|
1186
|
+
remote_control_command("dragAndDrop", [locator,movementsString,])
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
|
1190
|
+
# Drags an element and drops it on another element
|
1191
|
+
#
|
1192
|
+
# 'locatorOfObjectToBeDragged' is an element to be dragged
|
1193
|
+
# 'locatorOfDragDestinationObject' is an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
|
1194
|
+
def drag_and_drop_to_object(locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
|
1195
|
+
remote_control_command("dragAndDropToObject", [locatorOfObjectToBeDragged,locatorOfDragDestinationObject,])
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
|
1199
|
+
# Gives focus to the currently selected window
|
1200
|
+
#
|
1201
|
+
def window_focus()
|
1202
|
+
remote_control_command("windowFocus", [])
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
|
1206
|
+
# Resize currently selected window to take up the entire screen
|
1207
|
+
#
|
1208
|
+
def window_maximize()
|
1209
|
+
remote_control_command("windowMaximize", [])
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
|
1213
|
+
# Returns the IDs of all windows that the browser knows about in an array.
|
1214
|
+
#
|
1215
|
+
def get_all_window_ids()
|
1216
|
+
return string_array_command("getAllWindowIds", [])
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
|
1220
|
+
# Returns the names of all windows that the browser knows about in an array.
|
1221
|
+
#
|
1222
|
+
def get_all_window_names()
|
1223
|
+
return string_array_command("getAllWindowNames", [])
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
|
1227
|
+
# Returns the titles of all windows that the browser knows about in an array.
|
1228
|
+
#
|
1229
|
+
def get_all_window_titles()
|
1230
|
+
return string_array_command("getAllWindowTitles", [])
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
|
1234
|
+
# Returns the entire HTML source between the opening and
|
1235
|
+
# closing "html" tags.
|
1236
|
+
#
|
1237
|
+
def get_html_source()
|
1238
|
+
return string_command("getHtmlSource", [])
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
|
1242
|
+
# Moves the text cursor to the specified position in the given input element or textarea.
|
1243
|
+
# This method will fail if the specified element isn't an input element or textarea.
|
1244
|
+
#
|
1245
|
+
# 'locator' is an element locator pointing to an input element or textarea
|
1246
|
+
# 'position' is the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
|
1247
|
+
def set_cursor_position(locator,position)
|
1248
|
+
remote_control_command("setCursorPosition", [locator,position,])
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
|
1252
|
+
# Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
|
1253
|
+
# will be ignored.
|
1254
|
+
#
|
1255
|
+
# 'locator' is an element locator pointing to an element
|
1256
|
+
def get_element_index(locator)
|
1257
|
+
return number_command("getElementIndex", [locator,])
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
|
1261
|
+
# Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will
|
1262
|
+
# not be considered ordered.
|
1263
|
+
#
|
1264
|
+
# 'locator1' is an element locator pointing to the first element
|
1265
|
+
# 'locator2' is an element locator pointing to the second element
|
1266
|
+
def is_ordered(locator1,locator2)
|
1267
|
+
return boolean_command("isOrdered", [locator1,locator2,])
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
|
1271
|
+
# Retrieves the horizontal position of an element
|
1272
|
+
#
|
1273
|
+
# 'locator' is an element locator pointing to an element OR an element itself
|
1274
|
+
def get_element_position_left(locator)
|
1275
|
+
return number_command("getElementPositionLeft", [locator,])
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
|
1279
|
+
# Retrieves the vertical position of an element
|
1280
|
+
#
|
1281
|
+
# 'locator' is an element locator pointing to an element OR an element itself
|
1282
|
+
def get_element_position_top(locator)
|
1283
|
+
return number_command("getElementPositionTop", [locator,])
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
|
1287
|
+
# Retrieves the width of an element
|
1288
|
+
#
|
1289
|
+
# 'locator' is an element locator pointing to an element
|
1290
|
+
def get_element_width(locator)
|
1291
|
+
return number_command("getElementWidth", [locator,])
|
1292
|
+
end
|
1293
|
+
|
1294
|
+
|
1295
|
+
# Retrieves the height of an element
|
1296
|
+
#
|
1297
|
+
# 'locator' is an element locator pointing to an element
|
1298
|
+
def get_element_height(locator)
|
1299
|
+
return number_command("getElementHeight", [locator,])
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
|
1303
|
+
# Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
|
1304
|
+
#
|
1305
|
+
# Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
|
1306
|
+
# return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243.
|
1307
|
+
#
|
1308
|
+
# This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
|
1309
|
+
#
|
1310
|
+
# 'locator' is an element locator pointing to an input element or textarea
|
1311
|
+
def get_cursor_position(locator)
|
1312
|
+
return number_command("getCursorPosition", [locator,])
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
|
1316
|
+
# Returns the specified expression.
|
1317
|
+
#
|
1318
|
+
# This is useful because of JavaScript preprocessing.
|
1319
|
+
# It is used to generate commands like assertExpression and waitForExpression.
|
1320
|
+
#
|
1321
|
+
#
|
1322
|
+
# 'expression' is the value to return
|
1323
|
+
def get_expression(expression)
|
1324
|
+
return string_command("getExpression", [expression,])
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
|
1328
|
+
# Returns the number of nodes that match the specified xpath, eg. "//table" would give
|
1329
|
+
# the number of tables.
|
1330
|
+
#
|
1331
|
+
# 'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
|
1332
|
+
def get_xpath_count(xpath)
|
1333
|
+
return number_command("getXpathCount", [xpath,])
|
1334
|
+
end
|
1335
|
+
|
1336
|
+
|
1337
|
+
# Temporarily sets the "id" attribute of the specified element, so you can locate it in the future
|
1338
|
+
# using its ID rather than a slow/complicated XPath. This ID will disappear once the page is
|
1339
|
+
# reloaded.
|
1340
|
+
#
|
1341
|
+
# 'locator' is an element locator pointing to an element
|
1342
|
+
# 'identifier' is a string to be used as the ID of the specified element
|
1343
|
+
def assign_id(locator,identifier)
|
1344
|
+
remote_control_command("assignId", [locator,identifier,])
|
1345
|
+
end
|
1346
|
+
|
1347
|
+
|
1348
|
+
# Specifies whether Selenium should use the native in-browser implementation
|
1349
|
+
# of XPath (if any native version is available); if you pass "false" to
|
1350
|
+
# this function, we will always use our pure-JavaScript xpath library.
|
1351
|
+
# Using the pure-JS xpath library can improve the consistency of xpath
|
1352
|
+
# element locators between different browser vendors, but the pure-JS
|
1353
|
+
# version is much slower than the native implementations.
|
1354
|
+
#
|
1355
|
+
# 'allow' is boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
|
1356
|
+
def allow_native_xpath(allow)
|
1357
|
+
remote_control_command("allowNativeXpath", [allow,])
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
|
1361
|
+
# Specifies whether Selenium will ignore xpath attributes that have no
|
1362
|
+
# value, i.e. are the empty string, when using the non-native xpath
|
1363
|
+
# evaluation engine. You'd want to do this for performance reasons in IE.
|
1364
|
+
# However, this could break certain xpaths, for example an xpath that looks
|
1365
|
+
# for an attribute whose value is NOT the empty string.
|
1366
|
+
#
|
1367
|
+
# The hope is that such xpaths are relatively rare, but the user should
|
1368
|
+
# have the option of using them. Note that this only influences xpath
|
1369
|
+
# evaluation when using the ajaxslt engine (i.e. not "javascript-xpath").
|
1370
|
+
#
|
1371
|
+
# 'ignore' is boolean, true means we'll ignore attributes without value at the expense of xpath "correctness"; false means we'll sacrifice speed for correctness.
|
1372
|
+
def ignore_attributes_without_value(ignore)
|
1373
|
+
remote_control_command("ignoreAttributesWithoutValue", [ignore,])
|
1374
|
+
end
|
1375
|
+
|
1376
|
+
|
1377
|
+
# Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
|
1378
|
+
# The snippet may have multiple lines, but only the result of the last line
|
1379
|
+
# will be considered.
|
1380
|
+
#
|
1381
|
+
# Note that, by default, the snippet will be run in the runner's test window, not in the window
|
1382
|
+
# of your application. To get the window of your application, you can use
|
1383
|
+
# the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
|
1384
|
+
# run your JavaScript in there
|
1385
|
+
#
|
1386
|
+
#
|
1387
|
+
# 'script' is the JavaScript snippet to run
|
1388
|
+
# 'timeout' is a timeout in milliseconds, after which this command will return with an error
|
1389
|
+
def wait_for_condition(script,timeout)
|
1390
|
+
remote_control_command("waitForCondition", [script,timeout,])
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
|
1394
|
+
# Specifies the amount of time that Selenium will wait for actions to complete.
|
1395
|
+
#
|
1396
|
+
# Actions that require waiting include "open" and the "waitFor*" actions.
|
1397
|
+
#
|
1398
|
+
# The default timeout is 30 seconds.
|
1399
|
+
#
|
1400
|
+
# 'timeout' is a timeout in milliseconds, after which the action will return with an error
|
1401
|
+
def set_timeout(timeout)
|
1402
|
+
remote_control_command("setTimeout", [timeout,])
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
|
1406
|
+
# Waits for a new page to load.
|
1407
|
+
#
|
1408
|
+
# You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
|
1409
|
+
# (which are only available in the JS API).
|
1410
|
+
# Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
|
1411
|
+
# flag when it first notices a page load. Running any other Selenium command after
|
1412
|
+
# turns the flag to false. Hence, if you want to wait for a page to load, you must
|
1413
|
+
# wait immediately after a Selenium command that caused a page-load.
|
1414
|
+
#
|
1415
|
+
#
|
1416
|
+
# 'timeout' is a timeout in milliseconds, after which this command will return with an error
|
1417
|
+
def wait_for_page_to_load(timeout)
|
1418
|
+
remote_control_command("waitForPageToLoad", [timeout,])
|
1419
|
+
end
|
1420
|
+
|
1421
|
+
|
1422
|
+
# Waits for a new frame to load.
|
1423
|
+
#
|
1424
|
+
# Selenium constantly keeps track of new pages and frames loading,
|
1425
|
+
# and sets a "newPageLoaded" flag when it first notices a page load.
|
1426
|
+
#
|
1427
|
+
#
|
1428
|
+
# See waitForPageToLoad for more information.
|
1429
|
+
#
|
1430
|
+
# 'frameAddress' is FrameAddress from the server side
|
1431
|
+
# 'timeout' is a timeout in milliseconds, after which this command will return with an error
|
1432
|
+
def wait_for_frame_to_load(frameAddress,timeout)
|
1433
|
+
remote_control_command("waitForFrameToLoad", [frameAddress,timeout,])
|
1434
|
+
end
|
1435
|
+
|
1436
|
+
|
1437
|
+
# Return all cookies of the current page under test.
|
1438
|
+
#
|
1439
|
+
def get_cookie()
|
1440
|
+
return string_command("getCookie", [])
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
|
1444
|
+
# Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
|
1445
|
+
#
|
1446
|
+
# 'name' is the name of the cookie
|
1447
|
+
def get_cookie_by_name(name)
|
1448
|
+
return string_command("getCookieByName", [name,])
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
|
1452
|
+
# Returns true if a cookie with the specified name is present, or false otherwise.
|
1453
|
+
#
|
1454
|
+
# 'name' is the name of the cookie
|
1455
|
+
def is_cookie_present(name)
|
1456
|
+
return boolean_command("isCookiePresent", [name,])
|
1457
|
+
end
|
1458
|
+
|
1459
|
+
|
1460
|
+
# Create a new cookie whose path and domain are same with those of current page
|
1461
|
+
# under test, unless you specified a path for this cookie explicitly.
|
1462
|
+
#
|
1463
|
+
# 'nameValuePair' is name and value of the cookie in a format "name=value"
|
1464
|
+
# 'optionsString' is options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'. the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
|
1465
|
+
def create_cookie(nameValuePair,optionsString)
|
1466
|
+
remote_control_command("createCookie", [nameValuePair,optionsString,])
|
1467
|
+
end
|
1468
|
+
|
1469
|
+
|
1470
|
+
# Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
|
1471
|
+
# need to delete it using the exact same path and domain that were used to create the cookie.
|
1472
|
+
# If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
|
1473
|
+
# note that specifying a domain that isn't a subset of the current domain will usually fail.
|
1474
|
+
#
|
1475
|
+
# Since there's no way to discover at runtime the original path and domain of a given cookie,
|
1476
|
+
# we've added an option called 'recurse' to try all sub-domains of the current domain with
|
1477
|
+
# all paths that are a subset of the current path. Beware; this option can be slow. In
|
1478
|
+
# big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain
|
1479
|
+
# name and m is the number of slashes in the path.
|
1480
|
+
#
|
1481
|
+
# 'name' is the name of the cookie to be deleted
|
1482
|
+
# 'optionsString' is options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
|
1483
|
+
def delete_cookie(name,optionsString)
|
1484
|
+
remote_control_command("deleteCookie", [name,optionsString,])
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
|
1488
|
+
# Calls deleteCookie with recurse=true on all cookies visible to the current page.
|
1489
|
+
# As noted on the documentation for deleteCookie, recurse=true can be much slower
|
1490
|
+
# than simply deleting the cookies using a known domain/path.
|
1491
|
+
#
|
1492
|
+
def delete_all_visible_cookies()
|
1493
|
+
remote_control_command("deleteAllVisibleCookies", [])
|
1494
|
+
end
|
1495
|
+
|
1496
|
+
|
1497
|
+
# Sets the threshold for browser-side logging messages; log messages beneath this threshold will be discarded.
|
1498
|
+
# Valid logLevel strings are: "debug", "info", "warn", "error" or "off".
|
1499
|
+
# To see the browser logs, you need to
|
1500
|
+
# either show the log window in GUI mode, or enable browser-side logging in Selenium RC.
|
1501
|
+
#
|
1502
|
+
# 'logLevel' is one of the following: "debug", "info", "warn", "error" or "off"
|
1503
|
+
def set_browser_log_level(logLevel)
|
1504
|
+
remote_control_command("setBrowserLogLevel", [logLevel,])
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
|
1508
|
+
# Creates a new "script" tag in the body of the current test window, and
|
1509
|
+
# adds the specified text into the body of the command. Scripts run in
|
1510
|
+
# this way can often be debugged more easily than scripts executed using
|
1511
|
+
# Selenium's "getEval" command. Beware that JS exceptions thrown in these script
|
1512
|
+
# tags aren't managed by Selenium, so you should probably wrap your script
|
1513
|
+
# in try/catch blocks if there is any chance that the script will throw
|
1514
|
+
# an exception.
|
1515
|
+
#
|
1516
|
+
# 'script' is the JavaScript snippet to run
|
1517
|
+
def run_script(script)
|
1518
|
+
remote_control_command("runScript", [script,])
|
1519
|
+
end
|
1520
|
+
|
1521
|
+
|
1522
|
+
# Defines a new function for Selenium to locate elements on the page.
|
1523
|
+
# For example,
|
1524
|
+
# if you define the strategy "foo", and someone runs click("foo=blah"), we'll
|
1525
|
+
# run your function, passing you the string "blah", and click on the element
|
1526
|
+
# that your function
|
1527
|
+
# returns, or throw an "Element not found" error if your function returns null.
|
1528
|
+
#
|
1529
|
+
# We'll pass three arguments to your function:
|
1530
|
+
# * locator: the string the user passed in
|
1531
|
+
# * inWindow: the currently selected window
|
1532
|
+
# * inDocument: the currently selected document
|
1533
|
+
#
|
1534
|
+
#
|
1535
|
+
# The function must return null if the element can't be found.
|
1536
|
+
#
|
1537
|
+
# 'strategyName' is the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation.
|
1538
|
+
# 'functionDefinition' is a string defining the body of a function in JavaScript. For example: <tt>return inDocument.getElementById(locator);</tt>
|
1539
|
+
def add_location_strategy(strategyName,functionDefinition)
|
1540
|
+
remote_control_command("addLocationStrategy", [strategyName,functionDefinition,])
|
1541
|
+
end
|
1542
|
+
|
1543
|
+
|
1544
|
+
# Saves the entire contents of the current window canvas to a PNG file.
|
1545
|
+
# Contrast this with the captureScreenshot command, which captures the
|
1546
|
+
# contents of the OS viewport (i.e. whatever is currently being displayed
|
1547
|
+
# on the monitor), and is implemented in the RC only. Currently this only
|
1548
|
+
# works in Firefox when running in chrome mode, and in IE non-HTA using
|
1549
|
+
# the EXPERIMENTAL "Snapsie" utility. The Firefox implementation is mostly
|
1550
|
+
# borrowed from the Screengrab! Firefox extension. Please see
|
1551
|
+
# http://www.screengrab.org and http://snapsie.sourceforge.net/ for
|
1552
|
+
# details.
|
1553
|
+
#
|
1554
|
+
# 'filename' is the path to the file to persist the screenshot as. No filename extension will be appended by default. Directories will not be created if they do not exist, and an exception will be thrown, possibly by native code.
|
1555
|
+
# 'kwargs' is a kwargs string that modifies the way the screenshot is captured. Example: "background=#CCFFDD" . Currently valid options: * background:: the background CSS for the HTML document. This may be useful to set for capturing screenshots of less-than-ideal layouts, for example where absolute positioning causes the calculation of the canvas dimension to fail and a black background is exposed (possibly obscuring black text).
|
1556
|
+
def capture_entire_page_screenshot(filename,kwargs)
|
1557
|
+
remote_control_command("captureEntirePageScreenshot", [filename,kwargs,])
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
|
1561
|
+
# Executes a command rollup, which is a series of commands with a unique
|
1562
|
+
# name, and optionally arguments that control the generation of the set of
|
1563
|
+
# commands. If any one of the rolled-up commands fails, the rollup is
|
1564
|
+
# considered to have failed. Rollups may also contain nested rollups.
|
1565
|
+
#
|
1566
|
+
# 'rollupName' is the name of the rollup command
|
1567
|
+
# 'kwargs' is keyword arguments string that influences how the rollup expands into commands
|
1568
|
+
def rollup(rollupName,kwargs)
|
1569
|
+
remote_control_command("rollup", [rollupName,kwargs,])
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
|
1573
|
+
# Loads script content into a new script tag in the Selenium document. This
|
1574
|
+
# differs from the runScript command in that runScript adds the script tag
|
1575
|
+
# to the document of the AUT, not the Selenium document. The following
|
1576
|
+
# entities in the script content are replaced by the characters they
|
1577
|
+
# represent:
|
1578
|
+
#
|
1579
|
+
# <
|
1580
|
+
# >
|
1581
|
+
# &
|
1582
|
+
#
|
1583
|
+
# The corresponding remove command is removeScript.
|
1584
|
+
#
|
1585
|
+
# 'scriptContent' is the Javascript content of the script to add
|
1586
|
+
# 'scriptTagId' is (optional) the id of the new script tag. If specified, and an element with this id already exists, this operation will fail.
|
1587
|
+
def add_script(scriptContent,scriptTagId)
|
1588
|
+
remote_control_command("addScript", [scriptContent,scriptTagId,])
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
|
1592
|
+
# Removes a script tag from the Selenium document identified by the given
|
1593
|
+
# id. Does nothing if the referenced tag doesn't exist.
|
1594
|
+
#
|
1595
|
+
# 'scriptTagId' is the id of the script element to remove.
|
1596
|
+
def remove_script(scriptTagId)
|
1597
|
+
remote_control_command("removeScript", [scriptTagId,])
|
1598
|
+
end
|
1599
|
+
|
1600
|
+
|
1601
|
+
# Allows choice of one of the available libraries.
|
1602
|
+
#
|
1603
|
+
# 'libraryName' is name of the desired library Only the following three can be chosen: * "ajaxslt" - Google's library* "javascript-xpath" - Cybozu Labs' faster library* "default" - The default library. Currently the default library is "ajaxslt" . If libraryName isn't one of these three, then no change will be made.
|
1604
|
+
def use_xpath_library(libraryName)
|
1605
|
+
remote_control_command("useXpathLibrary", [libraryName,])
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
|
1609
|
+
# Writes a message to the status bar and adds a note to the browser-side
|
1610
|
+
# log.
|
1611
|
+
#
|
1612
|
+
# 'context' is the message to be sent to the browser
|
1613
|
+
def set_context(context)
|
1614
|
+
remote_control_command("setContext", [context,])
|
1615
|
+
end
|
1616
|
+
|
1617
|
+
|
1618
|
+
# Sets a file input (upload) field to the file listed in fileLocator
|
1619
|
+
#
|
1620
|
+
# 'fieldLocator' is an element locator
|
1621
|
+
# 'fileLocator' is a URL pointing to the specified file. Before the file can be set in the input field (fieldLocator), Selenium RC may need to transfer the file to the local machine before attaching the file in a web page form. This is common in selenium grid configurations where the RC server driving the browser is not the same machine that started the test. Supported Browsers: Firefox ("*chrome") only.
|
1622
|
+
def attach_file(fieldLocator,fileLocator)
|
1623
|
+
remote_control_command("attachFile", [fieldLocator,fileLocator,])
|
1624
|
+
end
|
1625
|
+
|
1626
|
+
|
1627
|
+
# Captures a PNG screenshot to the specified file.
|
1628
|
+
#
|
1629
|
+
# 'filename' is the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"
|
1630
|
+
def capture_screenshot(filename)
|
1631
|
+
remote_control_command("captureScreenshot", [filename,])
|
1632
|
+
end
|
1633
|
+
|
1634
|
+
|
1635
|
+
# Capture a PNG screenshot. It then returns the file as a base 64 encoded string.
|
1636
|
+
#
|
1637
|
+
def capture_screenshot_to_string()
|
1638
|
+
return string_command("captureScreenshotToString", [])
|
1639
|
+
end
|
1640
|
+
|
1641
|
+
|
1642
|
+
# Downloads a screenshot of the browser current window canvas to a
|
1643
|
+
# based 64 encoded PNG file. The <em>entire</em> windows canvas is captured,
|
1644
|
+
# including parts rendered outside of the current view port.
|
1645
|
+
#
|
1646
|
+
# Currently this only works in Mozilla and when running in chrome mode.
|
1647
|
+
#
|
1648
|
+
# 'kwargs' is A kwargs string that modifies the way the screenshot is captured. Example: "background=#CCFFDD". This may be useful to set for capturing screenshots of less-than-ideal layouts, for example where absolute positioning causes the calculation of the canvas dimension to fail and a black background is exposed (possibly obscuring black text).
|
1649
|
+
def capture_entire_page_screenshot_to_string(kwargs)
|
1650
|
+
return string_command("captureEntirePageScreenshotToString", [kwargs,])
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
|
1654
|
+
# Kills the running Selenium Server and all browser sessions. After you run this command, you will no longer be able to send
|
1655
|
+
# commands to the server; you can't remotely start the server once it has been stopped. Normally
|
1656
|
+
# you should prefer to run the "stop" command, which terminates the current browser session, rather than
|
1657
|
+
# shutting down the entire server.
|
1658
|
+
#
|
1659
|
+
def shut_down_selenium_server()
|
1660
|
+
remote_control_command("shutDownSeleniumServer", [])
|
1661
|
+
end
|
1662
|
+
|
1663
|
+
|
1664
|
+
# Retrieve the last messages logged on a specific remote control. Useful for error reports, especially
|
1665
|
+
# when running multiple remote controls in a distributed environment. The maximum number of log messages
|
1666
|
+
# that can be retrieve is configured on remote control startup.
|
1667
|
+
#
|
1668
|
+
def retrieve_last_remote_control_logs()
|
1669
|
+
return string_command("retrieveLastRemoteControlLogs", [])
|
1670
|
+
end
|
1671
|
+
|
1672
|
+
|
1673
|
+
# Simulates a user pressing a key (without releasing it yet) by sending a native operating system keystroke.
|
1674
|
+
# This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
|
1675
|
+
# a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
|
1676
|
+
# metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
|
1677
|
+
# element, focus on the element first before running this command.
|
1678
|
+
#
|
1679
|
+
# 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
|
1680
|
+
def key_down_native(keycode)
|
1681
|
+
remote_control_command("keyDownNative", [keycode,])
|
1682
|
+
end
|
1683
|
+
|
1684
|
+
|
1685
|
+
# Simulates a user releasing a key by sending a native operating system keystroke.
|
1686
|
+
# This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
|
1687
|
+
# a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
|
1688
|
+
# metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
|
1689
|
+
# element, focus on the element first before running this command.
|
1690
|
+
#
|
1691
|
+
# 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
|
1692
|
+
def key_up_native(keycode)
|
1693
|
+
remote_control_command("keyUpNative", [keycode,])
|
1694
|
+
end
|
1695
|
+
|
1696
|
+
|
1697
|
+
# Simulates a user pressing and releasing a key by sending a native operating system keystroke.
|
1698
|
+
# This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
|
1699
|
+
# a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
|
1700
|
+
# metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
|
1701
|
+
# element, focus on the element first before running this command.
|
1702
|
+
#
|
1703
|
+
# 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
|
1704
|
+
def key_press_native(keycode)
|
1705
|
+
remote_control_command("keyPressNative", [keycode,])
|
1706
|
+
end
|
1707
|
+
|
1708
|
+
|
1709
|
+
end # GeneratedDriver
|
1710
|
+
end # Client
|
1711
|
+
end # Selenium
|