Selenium 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/selenium.rb CHANGED
@@ -10,4 +10,3 @@ require 'button'
10
10
  require 'link'
11
11
  require 'locator'
12
12
  require 'text_field'
13
-
@@ -12,5 +12,9 @@ class DirectoryListingPage
12
12
  def link_to_entry(text)
13
13
  Link.new(browser, "link=#{text}")
14
14
  end
15
+
16
+ def assert_page
17
+ @browser.get_title.should == 'Index of /'
18
+ end
15
19
  end
16
20
  end
@@ -0,0 +1,4 @@
1
+ module Selenium
2
+ class HtmlElement
3
+ end
4
+ end
data/lib/selenium/link.rb CHANGED
@@ -1,27 +1,41 @@
1
1
  module Selenium
2
- class Link
3
- attr_reader :browser
4
-
5
- def Link::by_id(browser, id)
6
- Link.new(browser, "id=#{id}")
2
+
3
+ # Link class that models the behavior of a link
4
+ class Link
5
+ attr_reader :browser
6
+
7
+ def Link::by_id(browser, id, target = nil)
8
+ Link.new(browser, "id=#{id}", target)
9
+ end
10
+
11
+ def Link::by_text(browser, text, target = nil)
12
+ Link.new(browser, "link=#{text}", target)
13
+ end
14
+
15
+ def initialize(browser, locator, target = nil)
16
+ @browser = browser
17
+ @locator = locator
18
+ @target = target
19
+ end
20
+
21
+ # click the link
22
+ def click
23
+ @browser.click(@locator)
24
+ end
25
+
26
+ # click the link and wait for page to load
27
+ def click_wait
28
+ click
29
+ @browser.wait_for_page_to_load
30
+ end
31
+
32
+ # click the link, wait for the page to load, and asserts the target that
33
+ # was passed in during initialization
34
+ def go
35
+ raise "target page not defined for link #{@locator}" unless @target
36
+ click_wait
37
+ @target.assert_on_page
38
+ @target
39
+ end
7
40
  end
8
-
9
- def Link::by_text(browser, text)
10
- Link.new(browser, "link=#{text}")
11
- end
12
-
13
- def initialize(browser, locator)
14
- @browser = browser
15
- @locator = locator
16
- end
17
-
18
- def click
19
- @browser.click(@locator)
20
- end
21
-
22
- def click_wait
23
- click
24
- @browser.wait_for_page_to_load
25
- end
26
- end
27
41
  end
@@ -23,99 +23,99 @@ require 'net/http'
23
23
  require 'uri'
24
24
  require 'cgi'
25
25
 
26
- # Defines an object that runs Selenium commands.
27
- #
28
- # ===Element Locators
29
- # Element Locators tell Selenium which HTML element a command refers to.
30
- # The format of a locator is:
31
- # <em>locatorType</em><b>=</b><em>argument</em>
32
- # We support the following strategies for locating elements:
33
- #
34
- # * <b>identifier</b>=<em>id</em>::
35
- # Select the element with the specified @id attribute. If no match is
36
- # found, select the first element whose @name attribute is <em>id</em>.
37
- # (This is normally the default; see below.)
38
- # * <b>id</b>=<em>id</em>::
39
- # Select the element with the specified @id attribute.
40
- # * <b>name</b>=<em>name</em>::
41
- # Select the first element with the specified @name attribute.
42
- #
43
- # * username
44
- # * name=username
45
- #
46
- #
47
- #
48
- # 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.
49
- #
50
- # * name=flavour value=chocolate
51
- #
52
- #
53
- # * <b>dom</b>=<em>javascriptExpression</em>::
54
- #
55
- # Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
56
- # Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
57
- # * dom=document.forms['myForm'].myDropdown
58
- # * dom=document.images[56]
59
- # * dom=function foo() { return document.links[1]; }; foo();
60
- #
61
- #
62
- #
63
- # * <b>xpath</b>=<em>xpathExpression</em>::
64
- # Locate an element using an XPath expression.
65
- # * xpath=//img[@alt='The image alt text']
66
- # * xpath=//table[@id='table1']//tr[4]/td[2]
67
- #
68
- #
69
- # * <b>link</b>=<em>textPattern</em>::
70
- # Select the link (anchor) element which contains text matching the
71
- # specified <em>pattern</em>.
72
- # * link=The link text
73
- #
74
- #
75
- # * <b>css</b>=<em>cssSelectorSyntax</em>::
76
- # 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.
77
- # * css=a[href="#id3"]
78
- # * css=span#firstChild + span
79
- #
80
- #
81
- #
82
- # 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).
83
- #
84
- #
85
- # Without an explicit locator prefix, Selenium uses the following default
86
- # strategies:
87
- #
88
- # * <b>dom</b>, for locators starting with "document."
89
- # * <b>xpath</b>, for locators starting with "//"
90
- # * <b>identifier</b>, otherwise
91
- #
92
- # ===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.
93
- # Filters look much like locators, ie.
94
- # <em>filterType</em><b>=</b><em>argument</em>Supported element-filters are:
95
- # <b>value=</b><em>valuePattern</em>
96
- #
97
- # 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>
98
- #
99
- # Selects a single element based on its position in the list (offset from zero).===String-match Patterns
100
- # Various Pattern syntaxes are available for matching string values:
101
- #
102
- # * <b>glob:</b><em>pattern</em>::
103
- # Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
104
- # kind of limited regular-expression syntax typically used in command-line
105
- # shells. In a glob pattern, "*" represents any sequence of characters, and "?"
106
- # represents any single character. Glob patterns match against the entire
107
- # string.
108
- # * <b>regexp:</b><em>regexp</em>::
109
- # Match a string using a regular-expression. The full power of JavaScript
110
- # regular-expressions is available.
111
- # * <b>exact:</b><em>string</em>::
112
- # Match a string exactly, verbatim, without any of that fancy wildcard
113
- # stuff.
114
- #
115
- #
116
- # If no pattern prefix is specified, Selenium assumes that it's a "glob"
117
- # pattern.
118
- #
26
+ # Defines an object that runs Selenium commands.
27
+ #
28
+ # ===Element Locators
29
+ # Element Locators tell Selenium which HTML element a command refers to.
30
+ # The format of a locator is:
31
+ # <em>locatorType</em><b>=</b><em>argument</em>
32
+ # We support the following strategies for locating elements:
33
+ #
34
+ # * <b>identifier</b>=<em>id</em>:
35
+ # Select the element with the specified @id attribute. If no match is
36
+ # found, select the first element whose @name attribute is <em>id</em>.
37
+ # (This is normally the default; see below.)
38
+ # * <b>id</b>=<em>id</em>:
39
+ # Select the element with the specified @id attribute.
40
+ # * <b>name</b>=<em>name</em>:
41
+ # Select the first element with the specified @name attribute.
42
+ # * username
43
+ # * name=username
44
+ #
45
+ # 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.
46
+ # * name=flavour value=chocolate
47
+ #
48
+ #
49
+ # * <b>dom</b>=<em>javascriptExpression</em>:
50
+ #
51
+ # Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
52
+ # Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
53
+ # * dom=document.forms['myForm'].myDropdown
54
+ # * dom=document.images[56]
55
+ # * dom=function foo() { return document.links[1]; }; foo();
56
+ #
57
+ #
58
+ # * <b>xpath</b>=<em>xpathExpression</em>:
59
+ # Locate an element using an XPath expression.
60
+ # * xpath=//img[@alt='The image alt text']
61
+ # * xpath=//table[@id='table1']//tr[4]/td[2]
62
+ # * xpath=//a[contains(@href,'#id1')]
63
+ # * xpath=//a[contains(@href,'#id1')]/@class
64
+ # * xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
65
+ # * xpath=//input[@name='name2' and @value='yes']
66
+ # * xpath=//*[text()="right"]
67
+ #
68
+ #
69
+ # * <b>link</b>=<em>textPattern</em>:
70
+ # Select the link (anchor) element which contains text matching the
71
+ # specified <em>pattern</em>.
72
+ # * link=The link text
73
+ #
74
+ #
75
+ # * <b>css</b>=<em>cssSelectorSyntax</em>:
76
+ # 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.
77
+ # * css=a[href="#id3"]
78
+ # * css=span#firstChild + span
79
+ #
80
+ # 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).
81
+ #
82
+ #
83
+ #
84
+ # Without an explicit locator prefix, Selenium uses the following default
85
+ # strategies:
86
+ #
87
+ # * <b>dom</b>, for locators starting with "document."
88
+ # * <b>xpath</b>, for locators starting with "//"
89
+ # * <b>identifier</b>, otherwise
90
+ #
91
+ # ===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.
92
+ # Filters look much like locators, ie.
93
+ # <em>filterType</em><b>=</b><em>argument</em>Supported element-filters are:
94
+ # <b>value=</b><em>valuePattern</em>
95
+ #
96
+ # 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>
97
+ #
98
+ # Selects a single element based on its position in the list (offset from zero).===String-match Patterns
99
+ # Various Pattern syntaxes are available for matching string values:
100
+ #
101
+ # * <b>glob:</b><em>pattern</em>:
102
+ # Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
103
+ # kind of limited regular-expression syntax typically used in command-line
104
+ # shells. In a glob pattern, "*" represents any sequence of characters, and "?"
105
+ # represents any single character. Glob patterns match against the entire
106
+ # string.
107
+ # * <b>regexp:</b><em>regexp</em>:
108
+ # Match a string using a regular-expression. The full power of JavaScript
109
+ # regular-expressions is available.
110
+ # * <b>exact:</b><em>string</em>:
111
+ #
112
+ # Match a string exactly, verbatim, without any of that fancy wildcard
113
+ # stuff.
114
+ #
115
+ #
116
+ # If no pattern prefix is specified, Selenium assumes that it's a "glob"
117
+ # pattern.
118
+ #
119
119
  #
120
120
  module Selenium
121
121
 
@@ -156,12 +156,12 @@ module Selenium
156
156
  command_string = command_string + "&sessionId=" + @session_id.to_s
157
157
  end
158
158
  #print "Requesting --->" + command_string + "\n"
159
- response, result = http.get(command_string)
160
- #print "RESULT: " + result + "\n\n"
161
- if (result[0..1] != "OK")
162
- raise SeleniumCommandError.new(command_string), result
159
+ response = http.get(command_string)
160
+ #print "RESULT: " + response.body + "\n\n"
161
+ if (response.body[0..1] != "OK")
162
+ raise SeleniumCommandError, response.body
163
163
  end
164
- return result
164
+ return response.body
165
165
  end
166
166
  end
167
167
 
@@ -232,1088 +232,1246 @@ module Selenium
232
232
  end
233
233
 
234
234
 
235
-
236
- # Clicks on a link, button, checkbox or radio button. If the click action
237
- # causes a new page to load (like a link usually does), call
238
- # waitForPageToLoad.
239
- #
240
- # 'locator' is an element locator
241
- def click(locator)
242
- do_command("click", [locator,])
243
- end
244
-
245
-
246
- # Double clicks on a link, button, checkbox or radio button. If the double click action
247
- # causes a new page to load (like a link usually does), call
248
- # waitForPageToLoad.
249
- #
250
- # 'locator' is an element locator
251
- def double_click(locator)
252
- do_command("doubleClick", [locator,])
253
- end
254
-
255
-
256
- # Clicks on a link, button, checkbox or radio button. If the click action
257
- # causes a new page to load (like a link usually does), call
258
- # waitForPageToLoad.
259
- #
260
- # 'locator' is an element locator
261
- # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
262
- def click_at(locator,coordString)
263
- do_command("clickAt", [locator,coordString,])
264
- end
265
-
266
-
267
- # Doubleclicks on a link, button, checkbox or radio button. If the action
268
- # causes a new page to load (like a link usually does), call
269
- # waitForPageToLoad.
270
- #
271
- # 'locator' is an element locator
272
- # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
273
- def double_click_at(locator,coordString)
274
- do_command("doubleClickAt", [locator,coordString,])
275
- end
276
-
277
-
278
- # Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
279
- # handler.
280
- #
281
- # 'locator' is an element locator
282
- # 'eventName' is the event name, e.g. "focus" or "blur"
283
- def fire_event(locator,eventName)
284
- do_command("fireEvent", [locator,eventName,])
285
- end
286
-
287
-
288
- # Simulates a user pressing and releasing a key.
289
- #
290
- # 'locator' is an element locator
291
- # '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".
292
- def key_press(locator,keySequence)
293
- do_command("keyPress", [locator,keySequence,])
294
- end
295
-
296
-
297
- # Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
298
- #
299
- def shift_key_down()
300
- do_command("shiftKeyDown", [])
301
- end
302
-
303
-
304
- # Release the shift key.
305
- #
306
- def shift_key_up()
307
- do_command("shiftKeyUp", [])
308
- end
309
-
310
-
311
- # Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
312
- #
313
- def meta_key_down()
314
- do_command("metaKeyDown", [])
315
- end
316
-
317
-
318
- # Release the meta key.
319
- #
320
- def meta_key_up()
321
- do_command("metaKeyUp", [])
322
- end
323
-
324
-
325
- # Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
326
- #
327
- def alt_key_down()
328
- do_command("altKeyDown", [])
329
- end
330
-
331
-
332
- # Release the alt key.
333
- #
334
- def alt_key_up()
335
- do_command("altKeyUp", [])
336
- end
337
-
338
-
339
- # Press the control key and hold it down until doControlUp() is called or a new page is loaded.
340
- #
341
- def control_key_down()
342
- do_command("controlKeyDown", [])
343
- end
344
-
345
-
346
- # Release the control key.
347
- #
348
- def control_key_up()
349
- do_command("controlKeyUp", [])
350
- end
351
-
352
-
353
- # Simulates a user pressing a key (without releasing it yet).
354
- #
355
- # 'locator' is an element locator
356
- # '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".
357
- def key_down(locator,keySequence)
358
- do_command("keyDown", [locator,keySequence,])
359
- end
360
-
361
-
362
- # Simulates a user releasing a key.
363
- #
364
- # 'locator' is an element locator
365
- # '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".
366
- def key_up(locator,keySequence)
367
- do_command("keyUp", [locator,keySequence,])
368
- end
369
-
370
-
371
- # Simulates a user hovering a mouse over the specified element.
372
- #
373
- # 'locator' is an element locator
374
- def mouse_over(locator)
375
- do_command("mouseOver", [locator,])
376
- end
377
-
378
-
379
- # Simulates a user moving the mouse pointer away from the specified element.
380
- #
381
- # 'locator' is an element locator
382
- def mouse_out(locator)
383
- do_command("mouseOut", [locator,])
384
- end
385
-
386
-
387
- # Simulates a user pressing the mouse button (without releasing it yet) on
388
- # the specified element.
389
- #
390
- # 'locator' is an element locator
391
- def mouse_down(locator)
392
- do_command("mouseDown", [locator,])
393
- end
394
-
395
-
396
- # Simulates a user pressing the mouse button (without releasing it yet) on
397
- # the specified element.
398
- #
399
- # 'locator' is an element locator
400
- # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
401
- def mouse_down_at(locator,coordString)
402
- do_command("mouseDownAt", [locator,coordString,])
403
- end
404
-
405
-
406
- # Simulates a user pressing the mouse button (without releasing it yet) on
407
- # the specified element.
408
- #
409
- # 'locator' is an element locator
410
- def mouse_up(locator)
411
- do_command("mouseUp", [locator,])
412
- end
413
-
414
-
415
- # Simulates a user pressing the mouse button (without releasing it yet) on
416
- # the specified element.
417
- #
418
- # 'locator' is an element locator
419
- # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
420
- def mouse_up_at(locator,coordString)
421
- do_command("mouseUpAt", [locator,coordString,])
422
- end
423
-
424
-
425
- # Simulates a user pressing the mouse button (without releasing it yet) on
426
- # the specified element.
427
- #
428
- # 'locator' is an element locator
429
- def mouse_move(locator)
430
- do_command("mouseMove", [locator,])
431
- end
432
-
433
-
434
- # Simulates a user pressing the mouse button (without releasing it yet) on
435
- # the specified element.
436
- #
437
- # 'locator' is an element locator
438
- # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
439
- def mouse_move_at(locator,coordString)
440
- do_command("mouseMoveAt", [locator,coordString,])
441
- end
442
-
443
-
444
- # Sets the value of an input field, as though you typed it in.
445
- #
446
- # Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
447
- # value should be the value of the option selected, not the visible text.
448
- #
449
- #
450
- # 'locator' is an element locator
451
- # 'value' is the value to type
452
- def type(locator,value)
453
- do_command("type", [locator,value,])
454
- end
455
-
456
-
457
- # 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.,
458
- # the delay is 0 milliseconds.
459
- #
460
- # 'value' is the number of milliseconds to pause after operation
461
- def set_speed(value)
462
- do_command("setSpeed", [value,])
463
- end
464
-
465
-
466
- # 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.,
467
- # the delay is 0 milliseconds.
468
- #
469
- # See also setSpeed.
470
- #
471
- def get_speed()
472
- do_command("getSpeed", [])
473
- end
474
-
475
-
476
- # Check a toggle-button (checkbox/radio)
477
- #
478
- # 'locator' is an element locator
479
- def check(locator)
480
- do_command("check", [locator,])
481
- end
482
-
483
-
484
- # Uncheck a toggle-button (checkbox/radio)
485
- #
486
- # 'locator' is an element locator
487
- def uncheck(locator)
488
- do_command("uncheck", [locator,])
489
- end
490
-
491
-
492
- # Select an option from a drop-down using an option locator.
493
- #
494
- #
495
- # Option locators provide different ways of specifying options of an HTML
496
- # Select element (e.g. for selecting a specific option, or for asserting
497
- # that the selected option satisfies a specification). There are several
498
- # forms of Select Option Locator.
499
- #
500
- # * <b>label</b>=<em>labelPattern</em>::
501
- # matches options based on their labels, i.e. the visible text. (This
502
- # is the default.)
503
- # * label=regexp:^[Oo]ther
504
- #
505
- #
506
- # * <b>value</b>=<em>valuePattern</em>::
507
- # matches options based on their values.
508
- # * value=other
509
- #
510
- #
511
- # * <b>id</b>=<em>id</em>::
512
- # matches options based on their ids.
513
- # * id=option1
514
- #
515
- #
516
- # * <b>index</b>=<em>index</em>::
517
- # matches an option based on its index (offset from zero).
518
- # * index=2
519
- #
520
- #
521
- #
522
- #
523
- # If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
524
- #
525
- #
526
- #
527
- # 'selectLocator' is an element locator identifying a drop-down menu
528
- # 'optionLocator' is an option locator (a label by default)
529
- def select(selectLocator,optionLocator)
530
- do_command("select", [selectLocator,optionLocator,])
531
- end
532
-
533
-
534
- # Add a selection to the set of selected options in a multi-select element using an option locator.
535
- #
536
- # @see #doSelect for details of option locators
537
- #
538
- # 'locator' is an element locator identifying a multi-select box
539
- # 'optionLocator' is an option locator (a label by default)
540
- def add_selection(locator,optionLocator)
541
- do_command("addSelection", [locator,optionLocator,])
542
- end
543
-
544
-
545
- # Remove a selection from the set of selected options in a multi-select element using an option locator.
546
- #
547
- # @see #doSelect for details of option locators
548
- #
549
- # 'locator' is an element locator identifying a multi-select box
550
- # 'optionLocator' is an option locator (a label by default)
551
- def remove_selection(locator,optionLocator)
552
- do_command("removeSelection", [locator,optionLocator,])
553
- end
554
-
555
-
556
- # Submit the specified form. This is particularly useful for forms without
557
- # submit buttons, e.g. single-input "Search" forms.
558
- #
559
- # 'formLocator' is an element locator for the form you want to submit
560
- def submit(formLocator)
561
- do_command("submit", [formLocator,])
562
- end
563
-
564
-
565
- # Opens an URL in the test frame. This accepts both relative and absolute
566
- # URLs.
567
- #
568
- # The "open" command waits for the page to load before proceeding,
569
- # ie. the "AndWait" suffix is implicit.
570
- #
571
- # <em>Note</em>: The URL must be on the same domain as the runner HTML
572
- # due to security restrictions in the browser (Same Origin Policy). If you
573
- # need to open an URL on another domain, use the Selenium Server to start a
574
- # new browser session on that domain.
575
- #
576
- # 'url' is the URL to open; may be relative or absolute
577
- def open(url)
578
- do_command("open", [url,])
579
- end
580
-
581
-
582
- # Opens a popup window (if a window with that ID isn't already open).
583
- # After opening the window, you'll need to select it using the selectWindow
584
- # command.
585
- #
586
- # 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).
587
- # In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
588
- # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
589
- #
590
- #
591
- # 'url' is the URL to open, which can be blank
592
- # 'windowID' is the JavaScript window ID of the window to select
593
- def open_window(url,windowID)
594
- do_command("openWindow", [url,windowID,])
595
- end
596
-
597
-
598
- # Selects a popup window; once a popup window has been selected, all
599
- # commands go to that window. To select the main window again, use null
600
- # as the target.
601
- #
602
- # Selenium has several strategies for finding the window object referred to by the "windowID" parameter.
603
- # 1.) if windowID is null, then it is assumed the user is referring to the original window instantiated by the browser).
604
- # 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
605
- # that this variable contains the return value from a call to the JavaScript window.open() method.
606
- # 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window objects. Each of these string
607
- # names matches the second parameter "windowName" past to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
608
- # (which selenium intercepts).
609
- # If you're having trouble figuring out what is the name of a window that you want to manipulate, look at the selenium log messages
610
- # which identify the names of windows created via window.open (and therefore intercepted by selenium). You will see messages
611
- # like the following for each window as it is opened:
612
- # <tt>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</tt>
613
- # 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).
614
- # (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
615
- # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
616
- #
617
- #
618
- # 'windowID' is the JavaScript window ID of the window to select
619
- def select_window(windowID)
620
- do_command("selectWindow", [windowID,])
621
- end
622
-
623
-
624
- # Selects a frame within the current window. (You may invoke this command
625
- # multiple times to select nested frames.) To select the parent frame, use
626
- # "relative=parent" as a locator; to select the top frame, use "relative=top".
627
- #
628
- # You may also use a DOM expression to identify the frame you want directly,
629
- # like this: <tt>dom=frames["main"].frames["subframe"]</tt>
630
- #
631
- #
632
- # 'locator' is an element locator identifying a frame or iframe
633
- def select_frame(locator)
634
- do_command("selectFrame", [locator,])
635
- end
636
-
637
-
638
- # Return the contents of the log.
639
- #
640
- # This is a placeholder intended to make the code generator make this API
641
- # available to clients. The selenium server will intercept this call, however,
642
- # and return its recordkeeping of log messages since the last call to this API.
643
- # Thus this code in JavaScript will never be called.
644
- # The reason I opted for a servercentric solution is to be able to support
645
- # multiple frames served from different domains, which would break a
646
- # centralized JavaScript logging mechanism under some conditions.
647
- #
648
- #
649
- def get_log_messages()
650
- return get_string("getLogMessages", [])
651
- end
652
-
653
-
654
- # Determine whether current/locator identify the frame containing this running code.
655
- #
656
- # This is useful in proxy injection mode, where this code runs in every
657
- # browser frame and window, and sometimes the selenium server needs to identify
658
- # the "current" frame. In this case, when the test calls selectFrame, this
659
- # routine is called for each frame to figure out which one has been selected.
660
- # The selected frame will return true, while all others will return false.
661
- #
662
- #
663
- # 'currentFrameString' is starting frame
664
- # 'target' is new frame (which might be relative to the current one)
665
- def get_whether_this_frame_match_frame_expression(currentFrameString,target)
666
- return get_boolean("getWhetherThisFrameMatchFrameExpression", [currentFrameString,target,])
667
- end
668
-
669
-
670
- # Determine whether currentWindowString plus target identify the window containing this running code.
671
- #
672
- # This is useful in proxy injection mode, where this code runs in every
673
- # browser frame and window, and sometimes the selenium server needs to identify
674
- # the "current" window. In this case, when the test calls selectWindow, this
675
- # routine is called for each window to figure out which one has been selected.
676
- # The selected window will return true, while all others will return false.
677
- #
678
- #
679
- # 'currentWindowString' is starting window
680
- # 'target' is new window (which might be relative to the current one, e.g., "_parent")
681
- def get_whether_this_window_match_window_expression(currentWindowString,target)
682
- return get_boolean("getWhetherThisWindowMatchWindowExpression", [currentWindowString,target,])
683
- end
684
-
685
-
686
- # Waits for a popup window to appear and load up.
687
- #
688
- # 'windowID' is the JavaScript window ID of the window that will appear
689
- # 'timeout' is a timeout in milliseconds, after which the action will return with an error
690
- def wait_for_pop_up(windowID,timeout)
691
- do_command("waitForPopUp", [windowID,timeout,])
692
- end
693
-
694
-
695
- # By default, Selenium's overridden window.confirm() function will
696
- # return true, as if the user had manually clicked OK. After running
697
- # this command, the next call to confirm() will return false, as if
698
- # the user had clicked Cancel.
699
- #
700
- def choose_cancel_on_next_confirmation()
701
- do_command("chooseCancelOnNextConfirmation", [])
702
- end
703
-
704
-
705
- # Instructs Selenium to return the specified answer string in response to
706
- # the next JavaScript prompt [window.prompt()].
707
- #
708
- # 'answer' is the answer to give in response to the prompt pop-up
709
- def answer_on_next_prompt(answer)
710
- do_command("answerOnNextPrompt", [answer,])
711
- end
712
-
713
-
714
- # Simulates the user clicking the "back" button on their browser.
715
- #
716
- def go_back()
717
- do_command("goBack", [])
718
- end
719
-
720
-
721
- # Simulates the user clicking the "Refresh" button on their browser.
722
- #
723
- def refresh()
724
- do_command("refresh", [])
725
- end
726
-
727
-
728
- # Simulates the user clicking the "close" button in the titlebar of a popup
729
- # window or tab.
730
- #
731
- def close()
732
- do_command("close", [])
733
- end
734
-
735
-
736
- # Has an alert occurred?
737
- #
738
- #
739
- # This function never throws an exception
740
- #
741
- #
742
- #
743
- def is_alert_present()
744
- return get_boolean("isAlertPresent", [])
745
- end
746
-
747
-
748
- # Has a prompt occurred?
749
- #
750
- #
751
- # This function never throws an exception
752
- #
753
- #
754
- #
755
- def is_prompt_present()
756
- return get_boolean("isPromptPresent", [])
757
- end
758
-
759
-
760
- # Has confirm() been called?
761
- #
762
- #
763
- # This function never throws an exception
764
- #
765
- #
766
- #
767
- def is_confirmation_present()
768
- return get_boolean("isConfirmationPresent", [])
769
- end
770
-
771
-
772
- # Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
773
- #
774
- # Getting an alert has the same effect as manually clicking OK. If an
775
- # alert is generated but you do not get/verify it, the next Selenium action
776
- # will fail.
777
- # NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
778
- # dialog.
779
- # NOTE: Selenium does NOT support JavaScript alerts that are generated in a
780
- # page's onload() event handler. In this case a visible dialog WILL be
781
- # generated and Selenium will hang until someone manually clicks OK.
782
- #
783
- #
784
- def get_alert()
785
- return get_string("getAlert", [])
786
- end
787
-
788
-
789
- # Retrieves the message of a JavaScript confirmation dialog generated during
790
- # the previous action.
791
- #
792
- #
793
- # By default, the confirm function will return true, having the same effect
794
- # as manually clicking OK. This can be changed by prior execution of the
795
- # chooseCancelOnNextConfirmation command. If an confirmation is generated
796
- # but you do not get/verify it, the next Selenium action will fail.
797
- #
798
- #
799
- # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
800
- # dialog.
801
- #
802
- #
803
- # NOTE: Selenium does NOT support JavaScript confirmations that are
804
- # generated in a page's onload() event handler. In this case a visible
805
- # dialog WILL be generated and Selenium will hang until you manually click
806
- # OK.
807
- #
808
- #
809
- #
810
- def get_confirmation()
811
- return get_string("getConfirmation", [])
812
- end
813
-
814
-
815
- # Retrieves the message of a JavaScript question prompt dialog generated during
816
- # the previous action.
817
- #
818
- # Successful handling of the prompt requires prior execution of the
819
- # answerOnNextPrompt command. If a prompt is generated but you
820
- # do not get/verify it, the next Selenium action will fail.
821
- # NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
822
- # dialog.
823
- # NOTE: Selenium does NOT support JavaScript prompts that are generated in a
824
- # page's onload() event handler. In this case a visible dialog WILL be
825
- # generated and Selenium will hang until someone manually clicks OK.
826
- #
827
- #
828
- def get_prompt()
829
- return get_string("getPrompt", [])
830
- end
831
-
832
-
833
- # Gets the absolute URL of the current page.
834
- #
835
- def get_location()
836
- return get_string("getLocation", [])
837
- end
838
-
839
-
840
- # Gets the title of the current page.
841
- #
842
- def get_title()
843
- return get_string("getTitle", [])
844
- end
845
-
846
-
847
- # Gets the entire text of the page.
848
- #
849
- def get_body_text()
850
- return get_string("getBodyText", [])
851
- end
852
-
853
-
854
- # Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
855
- # For checkbox/radio elements, the value will be "on" or "off" depending on
856
- # whether the element is checked or not.
857
- #
858
- # 'locator' is an element locator
859
- def get_value(locator)
860
- return get_string("getValue", [locator,])
861
- end
862
-
863
-
864
- # Gets the text of an element. This works for any element that contains
865
- # text. This command uses either the textContent (Mozilla-like browsers) or
866
- # the innerText (IE-like browsers) of the element, which is the rendered
867
- # text shown to the user.
868
- #
869
- # 'locator' is an element locator
870
- def get_text(locator)
871
- return get_string("getText", [locator,])
872
- end
873
-
874
-
875
- # Gets the result of evaluating the specified JavaScript snippet. The snippet may
876
- # have multiple lines, but only the result of the last line will be returned.
877
- #
878
- # Note that, by default, the snippet will run in the context of the "selenium"
879
- # object itself, so <tt>this</tt> will refer to the Selenium object, and <tt>window</tt> will
880
- # refer to the top-level runner test window, not the window of your application.
881
- # If you need a reference to the window of your application, you can refer
882
- # to <tt>this.browserbot.getCurrentWindow()</tt> and if you need to use
883
- # a locator to refer to a single element in your application page, you can
884
- # use <tt>this.page().findElement("foo")</tt> where "foo" is your locator.
885
- #
886
- #
887
- # 'script' is the JavaScript snippet to run
888
- def get_eval(script)
889
- return get_string("getEval", [script,])
890
- end
891
-
892
-
893
- # Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
894
- #
895
- # 'locator' is an element locator pointing to a checkbox or radio button
896
- def is_checked(locator)
897
- return get_boolean("isChecked", [locator,])
898
- end
899
-
900
-
901
- # Gets the text from a cell of a table. The cellAddress syntax
902
- # tableLocator.row.column, where row and column start at 0.
903
- #
904
- # 'tableCellAddress' is a cell address, e.g. "foo.1.4"
905
- def get_table(tableCellAddress)
906
- return get_string("getTable", [tableCellAddress,])
907
- end
908
-
909
-
910
- # Gets all option labels (visible text) for selected options in the specified select or multi-select element.
911
- #
912
- # 'selectLocator' is an element locator identifying a drop-down menu
913
- def get_selected_labels(selectLocator)
914
- return get_string_array("getSelectedLabels", [selectLocator,])
915
- end
916
-
917
-
918
- # Gets option label (visible text) for selected option in the specified select element.
919
- #
920
- # 'selectLocator' is an element locator identifying a drop-down menu
921
- def get_selected_label(selectLocator)
922
- return get_string("getSelectedLabel", [selectLocator,])
923
- end
924
-
925
-
926
- # Gets all option values (value attributes) for selected options in the specified select or multi-select element.
927
- #
928
- # 'selectLocator' is an element locator identifying a drop-down menu
929
- def get_selected_values(selectLocator)
930
- return get_string_array("getSelectedValues", [selectLocator,])
931
- end
932
-
933
-
934
- # Gets option value (value attribute) for selected option in the specified select element.
935
- #
936
- # 'selectLocator' is an element locator identifying a drop-down menu
937
- def get_selected_value(selectLocator)
938
- return get_string("getSelectedValue", [selectLocator,])
939
- end
940
-
941
-
942
- # Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
943
- #
944
- # 'selectLocator' is an element locator identifying a drop-down menu
945
- def get_selected_indexes(selectLocator)
946
- return get_string_array("getSelectedIndexes", [selectLocator,])
947
- end
948
-
949
-
950
- # Gets option index (option number, starting at 0) for selected option in the specified select element.
951
- #
952
- # 'selectLocator' is an element locator identifying a drop-down menu
953
- def get_selected_index(selectLocator)
954
- return get_string("getSelectedIndex", [selectLocator,])
955
- end
956
-
957
-
958
- # Gets all option element IDs for selected options in the specified select or multi-select element.
959
- #
960
- # 'selectLocator' is an element locator identifying a drop-down menu
961
- def get_selected_ids(selectLocator)
962
- return get_string_array("getSelectedIds", [selectLocator,])
963
- end
964
-
965
-
966
- # Gets option element ID for selected option in the specified select element.
967
- #
968
- # 'selectLocator' is an element locator identifying a drop-down menu
969
- def get_selected_id(selectLocator)
970
- return get_string("getSelectedId", [selectLocator,])
971
- end
972
-
973
-
974
- # Determines whether some option in a drop-down menu is selected.
975
- #
976
- # 'selectLocator' is an element locator identifying a drop-down menu
977
- def is_something_selected(selectLocator)
978
- return get_boolean("isSomethingSelected", [selectLocator,])
979
- end
980
-
981
-
982
- # Gets all option labels in the specified select drop-down.
983
- #
984
- # 'selectLocator' is an element locator identifying a drop-down menu
985
- def get_select_options(selectLocator)
986
- return get_string_array("getSelectOptions", [selectLocator,])
987
- end
988
-
989
-
990
- # Gets the value of an element attribute.
991
- #
992
- # 'attributeLocator' is an element locator followed by an
993
- def get_attribute(attributeLocator)
994
- return get_string("getAttribute", [attributeLocator,])
995
- end
996
-
997
-
998
- # Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
999
- #
1000
- # 'pattern' is a pattern to match with the text of the page
1001
- def is_text_present(pattern)
1002
- return get_boolean("isTextPresent", [pattern,])
1003
- end
1004
-
1005
-
1006
- # Verifies that the specified element is somewhere on the page.
1007
- #
1008
- # 'locator' is an element locator
1009
- def is_element_present(locator)
1010
- return get_boolean("isElementPresent", [locator,])
1011
- end
1012
-
1013
-
1014
- # Determines if the specified element is visible. An
1015
- # element can be rendered invisible by setting the CSS "visibility"
1016
- # property to "hidden", or the "display" property to "none", either for the
1017
- # element itself or one if its ancestors. This method will fail if
1018
- # the element is not present.
1019
- #
1020
- # 'locator' is an element locator
1021
- def is_visible(locator)
1022
- return get_boolean("isVisible", [locator,])
1023
- end
1024
-
1025
-
1026
- # Determines whether the specified input element is editable, ie hasn't been disabled.
1027
- # This method will fail if the specified element isn't an input element.
1028
- #
1029
- # 'locator' is an element locator
1030
- def is_editable(locator)
1031
- return get_boolean("isEditable", [locator,])
1032
- end
1033
-
1034
-
1035
- # Returns the IDs of all buttons on the page.
1036
- #
1037
- # If a given button has no ID, it will appear as "" in this array.
1038
- #
1039
- #
1040
- def get_all_buttons()
1041
- return get_string_array("getAllButtons", [])
1042
- end
1043
-
1044
-
1045
- # Returns the IDs of all links on the page.
1046
- #
1047
- # If a given link has no ID, it will appear as "" in this array.
1048
- #
1049
- #
1050
- def get_all_links()
1051
- return get_string_array("getAllLinks", [])
1052
- end
1053
-
1054
-
1055
- # Returns the IDs of all input fields on the page.
1056
- #
1057
- # If a given field has no ID, it will appear as "" in this array.
1058
- #
1059
- #
1060
- def get_all_fields()
1061
- return get_string_array("getAllFields", [])
1062
- end
1063
-
1064
-
1065
- # Returns every instance of some attribute from all known windows.
1066
- #
1067
- # 'attributeName' is name of an attribute on the windows
1068
- def get_attribute_from_all_windows(attributeName)
1069
- return get_string_array("getAttributeFromAllWindows", [attributeName,])
1070
- end
1071
-
1072
-
1073
- # deprecated - use dragAndDrop instead
1074
- #
1075
- # 'locator' is an element locator
1076
- # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1077
- def dragdrop(locator,movementsString)
1078
- do_command("dragdrop", [locator,movementsString,])
1079
- end
1080
-
1081
-
1082
- # Drags an element a certain distance and then drops it
1083
- #
1084
- # 'locator' is an element locator
1085
- # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1086
- def drag_and_drop(locator,movementsString)
1087
- do_command("dragAndDrop", [locator,movementsString,])
1088
- end
1089
-
1090
-
1091
- # Drags an element and drops it on another element
1092
- #
1093
- # 'locatorOfObjectToBeDragged' is an element to be dragged
1094
- # 'locatorOfDragDestinationObject' is an element whose location (i.e., whose top left corner) will be the point where locatorOfObjectToBeDragged is dropped
1095
- def drag_and_drop_to_object(locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
1096
- do_command("dragAndDropToObject", [locatorOfObjectToBeDragged,locatorOfDragDestinationObject,])
1097
- end
1098
-
1099
-
1100
- # Gives focus to a window
1101
- #
1102
- # 'windowName' is name of the window to be given focus
1103
- def window_focus(windowName)
1104
- do_command("windowFocus", [windowName,])
1105
- end
1106
-
1107
-
1108
- # Resize window to take up the entire screen
1109
- #
1110
- # 'windowName' is name of the window to be enlarged
1111
- def window_maximize(windowName)
1112
- do_command("windowMaximize", [windowName,])
1113
- end
1114
-
1115
-
1116
- # Returns the IDs of all windows that the browser knows about.
1117
- #
1118
- def get_all_window_ids()
1119
- return get_string_array("getAllWindowIds", [])
1120
- end
1121
-
1122
-
1123
- # Returns the names of all windows that the browser knows about.
1124
- #
1125
- def get_all_window_names()
1126
- return get_string_array("getAllWindowNames", [])
1127
- end
1128
-
1129
-
1130
- # Returns the titles of all windows that the browser knows about.
1131
- #
1132
- def get_all_window_titles()
1133
- return get_string_array("getAllWindowTitles", [])
1134
- end
1135
-
1136
-
1137
- # Returns the entire HTML source between the opening and
1138
- # closing "html" tags.
1139
- #
1140
- def get_html_source()
1141
- return get_string("getHtmlSource", [])
1142
- end
1143
-
1144
-
1145
- # Moves the text cursor to the specified position in the given input element or textarea.
1146
- # This method will fail if the specified element isn't an input element or textarea.
1147
- #
1148
- # 'locator' is an element locator pointing to an input element or textarea
1149
- # '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.
1150
- def set_cursor_position(locator,position)
1151
- do_command("setCursorPosition", [locator,position,])
1152
- end
1153
-
1154
-
1155
- # Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
1156
- # will be ignored.
1157
- #
1158
- # 'locator' is an element locator pointing to an element
1159
- def get_element_index(locator)
1160
- return get_number("getElementIndex", [locator,])
1161
- end
1162
-
1163
-
1164
- # Check if these two elements have same parent and are ordered. Two same elements will
1165
- # not be considered ordered.
1166
- #
1167
- # 'locator1' is an element locator pointing to the first element
1168
- # 'locator2' is an element locator pointing to the second element
1169
- def is_ordered(locator1,locator2)
1170
- return get_boolean("isOrdered", [locator1,locator2,])
1171
- end
1172
-
1173
-
1174
- # Retrieves the horizontal position of an element
1175
- #
1176
- # 'locator' is an element locator pointing to an element OR an element itself
1177
- def get_element_position_left(locator)
1178
- return get_number("getElementPositionLeft", [locator,])
1179
- end
1180
-
1181
-
1182
- # Retrieves the vertical position of an element
1183
- #
1184
- # 'locator' is an element locator pointing to an element OR an element itself
1185
- def get_element_position_top(locator)
1186
- return get_number("getElementPositionTop", [locator,])
1187
- end
1188
-
1189
-
1190
- # Retrieves the width of an element
1191
- #
1192
- # 'locator' is an element locator pointing to an element
1193
- def get_element_width(locator)
1194
- return get_number("getElementWidth", [locator,])
1195
- end
1196
-
1197
-
1198
- # Retrieves the height of an element
1199
- #
1200
- # 'locator' is an element locator pointing to an element
1201
- def get_element_height(locator)
1202
- return get_number("getElementHeight", [locator,])
1203
- end
1204
-
1205
-
1206
- # Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
1207
- #
1208
- # Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
1209
- # 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.
1210
- #
1211
- # This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
1212
- #
1213
- # 'locator' is an element locator pointing to an input element or textarea
1214
- def get_cursor_position(locator)
1215
- return get_number("getCursorPosition", [locator,])
1216
- end
1217
-
1218
-
1219
- # Writes a message to the status bar and adds a note to the browser-side
1220
- # log.
1221
- #
1222
- # If logLevelThreshold is specified, set the threshold for logging
1223
- # to that level (debug, info, warn, error).
1224
- # (Note that the browser-side logs will <em>not</em> be sent back to the
1225
- # server, and are invisible to the Client Driver.)
1226
- #
1227
- #
1228
- # 'context' is the message to be sent to the browser
1229
- # 'logLevelThreshold' is one of "debug", "info", "warn", "error", sets the threshold for browser-side logging
1230
- def set_context(context,logLevelThreshold)
1231
- do_command("setContext", [context,logLevelThreshold,])
1232
- end
1233
-
1234
-
1235
- # Returns the specified expression.
1236
- #
1237
- # This is useful because of JavaScript preprocessing.
1238
- # It is used to generate commands like assertExpression and waitForExpression.
1239
- #
1240
- #
1241
- # 'expression' is the value to return
1242
- def get_expression(expression)
1243
- return get_string("getExpression", [expression,])
1244
- end
1245
-
1246
-
1247
- # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
1248
- # The snippet may have multiple lines, but only the result of the last line
1249
- # will be considered.
1250
- #
1251
- # Note that, by default, the snippet will be run in the runner's test window, not in the window
1252
- # of your application. To get the window of your application, you can use
1253
- # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
1254
- # run your JavaScript in there
1255
- #
1256
- #
1257
- # 'script' is the JavaScript snippet to run
1258
- # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1259
- def wait_for_condition(script,timeout)
1260
- do_command("waitForCondition", [script,timeout,])
1261
- end
1262
-
1263
-
1264
- # Specifies the amount of time that Selenium will wait for actions to complete.
1265
- #
1266
- # Actions that require waiting include "open" and the "waitFor*" actions.
1267
- #
1268
- # The default timeout is 30 seconds.
1269
- #
1270
- # 'timeout' is a timeout in milliseconds, after which the action will return with an error
1271
- def set_timeout(timeout)
1272
- do_command("setTimeout", [timeout,])
1273
- end
1274
-
1275
-
1276
- # Waits for a new page to load.
1277
- #
1278
- # You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
1279
- # (which are only available in the JS API).
1280
- # Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
1281
- # flag when it first notices a page load. Running any other Selenium command after
1282
- # turns the flag to false. Hence, if you want to wait for a page to load, you must
1283
- # wait immediately after a Selenium command that caused a page-load.
1284
- #
1285
- #
1286
- # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1287
- def wait_for_page_to_load(timeout=@timeout)
1288
- do_command("waitForPageToLoad", [timeout,])
1289
- end
1290
-
1291
-
1292
- # Return all cookies of the current page under test.
1293
- #
1294
- def get_cookie()
1295
- return get_string("getCookie", [])
1296
- end
1297
-
1298
-
1299
- # Create a new cookie whose path and domain are same with those of current page
1300
- # under test, unless you specified a path for this cookie explicitly.
1301
- #
1302
- # 'nameValuePair' is name and value of the cookie in a format "name=value"
1303
- # 'optionsString' is options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
1304
- def create_cookie(nameValuePair,optionsString)
1305
- do_command("createCookie", [nameValuePair,optionsString,])
1306
- end
1307
-
1308
-
1309
- # Delete a named cookie with specified path.
1310
- #
1311
- # 'name' is the name of the cookie to be deleted
1312
- # 'path' is the path property of the cookie to be deleted
1313
- def delete_cookie(name,path)
1314
- do_command("deleteCookie", [name,path,])
1315
- end
1316
-
235
+
236
+ # Clicks on a link, button, checkbox or radio button. If the click action
237
+ # causes a new page to load (like a link usually does), call
238
+ # waitForPageToLoad.
239
+ #
240
+ # 'locator' is an element locator
241
+ def click(locator)
242
+ do_command("click", [locator,])
243
+ end
244
+
245
+
246
+ # Double clicks on a link, button, checkbox or radio button. If the double click action
247
+ # causes a new page to load (like a link usually does), call
248
+ # waitForPageToLoad.
249
+ #
250
+ # 'locator' is an element locator
251
+ def double_click(locator)
252
+ do_command("doubleClick", [locator,])
253
+ end
254
+
255
+
256
+ # Clicks on a link, button, checkbox or radio button. If the click action
257
+ # causes a new page to load (like a link usually does), call
258
+ # waitForPageToLoad.
259
+ #
260
+ # 'locator' is an element locator
261
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
262
+ def click_at(locator,coordString)
263
+ do_command("clickAt", [locator,coordString,])
264
+ end
265
+
266
+
267
+ # Doubleclicks on a link, button, checkbox or radio button. If the action
268
+ # causes a new page to load (like a link usually does), call
269
+ # waitForPageToLoad.
270
+ #
271
+ # 'locator' is an element locator
272
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
273
+ def double_click_at(locator,coordString)
274
+ do_command("doubleClickAt", [locator,coordString,])
275
+ end
276
+
277
+
278
+ # Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
279
+ # handler.
280
+ #
281
+ # 'locator' is an element locator
282
+ # 'eventName' is the event name, e.g. "focus" or "blur"
283
+ def fire_event(locator,eventName)
284
+ do_command("fireEvent", [locator,eventName,])
285
+ end
286
+
287
+
288
+ # Simulates a user pressing and releasing a key.
289
+ #
290
+ # 'locator' is an element locator
291
+ # '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".
292
+ def key_press(locator,keySequence)
293
+ do_command("keyPress", [locator,keySequence,])
294
+ end
295
+
296
+
297
+ # Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
298
+ #
299
+ def shift_key_down()
300
+ do_command("shiftKeyDown", [])
301
+ end
302
+
303
+
304
+ # Release the shift key.
305
+ #
306
+ def shift_key_up()
307
+ do_command("shiftKeyUp", [])
308
+ end
309
+
310
+
311
+ # Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
312
+ #
313
+ def meta_key_down()
314
+ do_command("metaKeyDown", [])
315
+ end
316
+
317
+
318
+ # Release the meta key.
319
+ #
320
+ def meta_key_up()
321
+ do_command("metaKeyUp", [])
322
+ end
323
+
324
+
325
+ # Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
326
+ #
327
+ def alt_key_down()
328
+ do_command("altKeyDown", [])
329
+ end
330
+
331
+
332
+ # Release the alt key.
333
+ #
334
+ def alt_key_up()
335
+ do_command("altKeyUp", [])
336
+ end
337
+
338
+
339
+ # Press the control key and hold it down until doControlUp() is called or a new page is loaded.
340
+ #
341
+ def control_key_down()
342
+ do_command("controlKeyDown", [])
343
+ end
344
+
345
+
346
+ # Release the control key.
347
+ #
348
+ def control_key_up()
349
+ do_command("controlKeyUp", [])
350
+ end
351
+
352
+
353
+ # Simulates a user pressing a key (without releasing it yet).
354
+ #
355
+ # 'locator' is an element locator
356
+ # '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".
357
+ def key_down(locator,keySequence)
358
+ do_command("keyDown", [locator,keySequence,])
359
+ end
360
+
361
+
362
+ # Simulates a user releasing a key.
363
+ #
364
+ # 'locator' is an element locator
365
+ # '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".
366
+ def key_up(locator,keySequence)
367
+ do_command("keyUp", [locator,keySequence,])
368
+ end
369
+
370
+
371
+ # Simulates a user hovering a mouse over the specified element.
372
+ #
373
+ # 'locator' is an element locator
374
+ def mouse_over(locator)
375
+ do_command("mouseOver", [locator,])
376
+ end
377
+
378
+
379
+ # Simulates a user moving the mouse pointer away from the specified element.
380
+ #
381
+ # 'locator' is an element locator
382
+ def mouse_out(locator)
383
+ do_command("mouseOut", [locator,])
384
+ end
385
+
386
+
387
+ # Simulates a user pressing the mouse button (without releasing it yet) on
388
+ # the specified element.
389
+ #
390
+ # 'locator' is an element locator
391
+ def mouse_down(locator)
392
+ do_command("mouseDown", [locator,])
393
+ end
394
+
395
+
396
+ # Simulates a user pressing the mouse button (without releasing it yet) at
397
+ # the specified location.
398
+ #
399
+ # 'locator' is an element locator
400
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
401
+ def mouse_down_at(locator,coordString)
402
+ do_command("mouseDownAt", [locator,coordString,])
403
+ end
404
+
405
+
406
+ # Simulates the event that occurs when the user releases the mouse button (i.e., stops
407
+ # holding the button down) on the specified element.
408
+ #
409
+ # 'locator' is an element locator
410
+ def mouse_up(locator)
411
+ do_command("mouseUp", [locator,])
412
+ end
413
+
414
+
415
+ # Simulates the event that occurs when the user releases the mouse button (i.e., stops
416
+ # holding the button down) at the specified location.
417
+ #
418
+ # 'locator' is an element locator
419
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
420
+ def mouse_up_at(locator,coordString)
421
+ do_command("mouseUpAt", [locator,coordString,])
422
+ end
423
+
424
+
425
+ # Simulates a user pressing the mouse button (without releasing it yet) on
426
+ # the specified element.
427
+ #
428
+ # 'locator' is an element locator
429
+ def mouse_move(locator)
430
+ do_command("mouseMove", [locator,])
431
+ end
432
+
433
+
434
+ # Simulates a user pressing the mouse button (without releasing it yet) on
435
+ # the specified element.
436
+ #
437
+ # 'locator' is an element locator
438
+ # 'coordString' is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
439
+ def mouse_move_at(locator,coordString)
440
+ do_command("mouseMoveAt", [locator,coordString,])
441
+ end
442
+
443
+
444
+ # Sets the value of an input field, as though you typed it in.
445
+ #
446
+ # Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
447
+ # value should be the value of the option selected, not the visible text.
448
+ #
449
+ #
450
+ # 'locator' is an element locator
451
+ # 'value' is the value to type
452
+ def type(locator,value)
453
+ do_command("type", [locator,value,])
454
+ end
455
+
456
+
457
+ # Simulates keystroke events on the specified element, as though you typed the value key-by-key.
458
+ #
459
+ # This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;
460
+ # this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
461
+ # Unlike the simple "type" command, which forces the specified value into the page directly, this command
462
+ # may or may not have any visible effect, even in cases where typing keys would normally have a visible effect.
463
+ # For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in
464
+ # the field.
465
+ # 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
466
+ # send the keystroke events corresponding to what you just typed.
467
+ #
468
+ #
469
+ # 'locator' is an element locator
470
+ # 'value' is the value to type
471
+ def type_keys(locator,value)
472
+ do_command("typeKeys", [locator,value,])
473
+ end
474
+
475
+
476
+ # 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.,
477
+ # the delay is 0 milliseconds.
478
+ #
479
+ # 'value' is the number of milliseconds to pause after operation
480
+ def set_speed(value)
481
+ do_command("setSpeed", [value,])
482
+ end
483
+
484
+
485
+ # 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.,
486
+ # the delay is 0 milliseconds.
487
+ #
488
+ # See also setSpeed.
489
+ #
490
+ def get_speed()
491
+ do_command("getSpeed", [])
492
+ end
493
+
494
+
495
+ # Check a toggle-button (checkbox/radio)
496
+ #
497
+ # 'locator' is an element locator
498
+ def check(locator)
499
+ do_command("check", [locator,])
500
+ end
501
+
502
+
503
+ # Uncheck a toggle-button (checkbox/radio)
504
+ #
505
+ # 'locator' is an element locator
506
+ def uncheck(locator)
507
+ do_command("uncheck", [locator,])
508
+ end
509
+
510
+
511
+ # Select an option from a drop-down using an option locator.
512
+ #
513
+ #
514
+ # Option locators provide different ways of specifying options of an HTML
515
+ # Select element (e.g. for selecting a specific option, or for asserting
516
+ # that the selected option satisfies a specification). There are several
517
+ # forms of Select Option Locator.
518
+ #
519
+ # * <b>label</b>=<em>labelPattern</em>:
520
+ # matches options based on their labels, i.e. the visible text. (This
521
+ # is the default.)
522
+ # * label=regexp:^[Oo]ther
523
+ #
524
+ #
525
+ # * <b>value</b>=<em>valuePattern</em>:
526
+ # matches options based on their values.
527
+ # * value=other
528
+ #
529
+ #
530
+ # * <b>id</b>=<em>id</em>:
531
+ #
532
+ # matches options based on their ids.
533
+ # * id=option1
534
+ #
535
+ #
536
+ # * <b>index</b>=<em>index</em>:
537
+ # matches an option based on its index (offset from zero).
538
+ # * index=2
539
+ #
540
+ #
541
+ #
542
+ #
543
+ # If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
544
+ #
545
+ #
546
+ #
547
+ # 'selectLocator' is an element locator identifying a drop-down menu
548
+ # 'optionLocator' is an option locator (a label by default)
549
+ def select(selectLocator,optionLocator)
550
+ do_command("select", [selectLocator,optionLocator,])
551
+ end
552
+
553
+
554
+ # Add a selection to the set of selected options in a multi-select element using an option locator.
555
+ #
556
+ # @see #doSelect for details of option locators
557
+ #
558
+ # 'locator' is an element locator identifying a multi-select box
559
+ # 'optionLocator' is an option locator (a label by default)
560
+ def add_selection(locator,optionLocator)
561
+ do_command("addSelection", [locator,optionLocator,])
562
+ end
563
+
564
+
565
+ # Remove a selection from the set of selected options in a multi-select element using an option locator.
566
+ #
567
+ # @see #doSelect for details of option locators
568
+ #
569
+ # 'locator' is an element locator identifying a multi-select box
570
+ # 'optionLocator' is an option locator (a label by default)
571
+ def remove_selection(locator,optionLocator)
572
+ do_command("removeSelection", [locator,optionLocator,])
573
+ end
574
+
575
+
576
+ # Unselects all of the selected options in a multi-select element.
577
+ #
578
+ # 'locator' is an element locator identifying a multi-select box
579
+ def remove_all_selections(locator)
580
+ do_command("removeAllSelections", [locator,])
581
+ end
582
+
583
+
584
+ # Submit the specified form. This is particularly useful for forms without
585
+ # submit buttons, e.g. single-input "Search" forms.
586
+ #
587
+ # 'formLocator' is an element locator for the form you want to submit
588
+ def submit(formLocator)
589
+ do_command("submit", [formLocator,])
590
+ end
591
+
592
+
593
+ # Opens an URL in the test frame. This accepts both relative and absolute
594
+ # URLs.
595
+ #
596
+ # The "open" command waits for the page to load before proceeding,
597
+ # ie. the "AndWait" suffix is implicit.
598
+ #
599
+ # <em>Note</em>: The URL must be on the same domain as the runner HTML
600
+ # due to security restrictions in the browser (Same Origin Policy). If you
601
+ # need to open an URL on another domain, use the Selenium Server to start a
602
+ # new browser session on that domain.
603
+ #
604
+ # 'url' is the URL to open; may be relative or absolute
605
+ def open(url)
606
+ do_command("open", [url,])
607
+ end
608
+
609
+
610
+ # Opens a popup window (if a window with that ID isn't already open).
611
+ # After opening the window, you'll need to select it using the selectWindow
612
+ # command.
613
+ #
614
+ # 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).
615
+ # In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
616
+ # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
617
+ #
618
+ #
619
+ # 'url' is the URL to open, which can be blank
620
+ # 'windowID' is the JavaScript window ID of the window to select
621
+ def open_window(url,windowID)
622
+ do_command("openWindow", [url,windowID,])
623
+ end
624
+
625
+
626
+ # Selects a popup window; once a popup window has been selected, all
627
+ # commands go to that window. To select the main window again, use null
628
+ # as the target.
629
+ #
630
+ # Note that there is a big difference between a window's internal JavaScript "name" property
631
+ # and the "title" of a given window's document (which is normally what you actually see, as an end user,
632
+ # in the title bar of the window). The "name" is normally invisible to the end-user; it's the second
633
+ # parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
634
+ # (which selenium intercepts).
635
+ # Selenium has several strategies for finding the window object referred to by the "windowID" parameter.
636
+ # 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).
637
+ # 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
638
+ # that this variable contains the return value from a call to the JavaScript window.open() method.
639
+ # 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".
640
+ # 4.) If <em>that</em> fails, we'll try looping over all of the known windows to try to find the appropriate "title".
641
+ # Since "title" is not necessarily unique, this may have unexpected behavior.
642
+ # If you're having trouble figuring out what is the name of a window that you want to manipulate, look at the selenium log messages
643
+ # which identify the names of windows created via window.open (and therefore intercepted by selenium). You will see messages
644
+ # like the following for each window as it is opened:
645
+ # <tt>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</tt>
646
+ # 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).
647
+ # (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
648
+ # an empty (blank) url, like this: openWindow("", "myFunnyWindow").
649
+ #
650
+ #
651
+ # 'windowID' is the JavaScript window ID of the window to select
652
+ def select_window(windowID)
653
+ do_command("selectWindow", [windowID,])
654
+ end
655
+
656
+
657
+ # Selects a frame within the current window. (You may invoke this command
658
+ # multiple times to select nested frames.) To select the parent frame, use
659
+ # "relative=parent" as a locator; to select the top frame, use "relative=top".
660
+ # You can also select a frame by its 0-based index number; select the first frame with
661
+ # "index=0", or the third frame with "index=2".
662
+ #
663
+ # You may also use a DOM expression to identify the frame you want directly,
664
+ # like this: <tt>dom=frames["main"].frames["subframe"]</tt>
665
+ #
666
+ #
667
+ # 'locator' is an element locator identifying a frame or iframe
668
+ def select_frame(locator)
669
+ do_command("selectFrame", [locator,])
670
+ end
671
+
672
+
673
+ # Determine whether current/locator identify the frame containing this running code.
674
+ #
675
+ # This is useful in proxy injection mode, where this code runs in every
676
+ # browser frame and window, and sometimes the selenium server needs to identify
677
+ # the "current" frame. In this case, when the test calls selectFrame, this
678
+ # routine is called for each frame to figure out which one has been selected.
679
+ # The selected frame will return true, while all others will return false.
680
+ #
681
+ #
682
+ # 'currentFrameString' is starting frame
683
+ # 'target' is new frame (which might be relative to the current one)
684
+ def get_whether_this_frame_match_frame_expression(currentFrameString,target)
685
+ return get_boolean("getWhetherThisFrameMatchFrameExpression", [currentFrameString,target,])
686
+ end
687
+
688
+
689
+ # Determine whether currentWindowString plus target identify the window containing this running code.
690
+ #
691
+ # This is useful in proxy injection mode, where this code runs in every
692
+ # browser frame and window, and sometimes the selenium server needs to identify
693
+ # the "current" window. In this case, when the test calls selectWindow, this
694
+ # routine is called for each window to figure out which one has been selected.
695
+ # The selected window will return true, while all others will return false.
696
+ #
697
+ #
698
+ # 'currentWindowString' is starting window
699
+ # 'target' is new window (which might be relative to the current one, e.g., "_parent")
700
+ def get_whether_this_window_match_window_expression(currentWindowString,target)
701
+ return get_boolean("getWhetherThisWindowMatchWindowExpression", [currentWindowString,target,])
702
+ end
703
+
704
+
705
+ # Waits for a popup window to appear and load up.
706
+ #
707
+ # 'windowID' is the JavaScript window ID of the window that will appear
708
+ # 'timeout' is a timeout in milliseconds, after which the action will return with an error
709
+ def wait_for_pop_up(windowID,timeout)
710
+ do_command("waitForPopUp", [windowID,timeout,])
711
+ end
712
+
713
+
714
+ # By default, Selenium's overridden window.confirm() function will
715
+ # return true, as if the user had manually clicked OK; after running
716
+ # this command, the next call to confirm() will return false, as if
717
+ # the user had clicked Cancel. Selenium will then resume using the
718
+ # default behavior for future confirmations, automatically returning
719
+ # true (OK) unless/until you explicitly call this command for each
720
+ # confirmation.
721
+ #
722
+ def choose_cancel_on_next_confirmation()
723
+ do_command("chooseCancelOnNextConfirmation", [])
724
+ end
725
+
726
+
727
+ # Undo the effect of calling chooseCancelOnNextConfirmation. Note
728
+ # that Selenium's overridden window.confirm() function will normally automatically
729
+ # return true, as if the user had manually clicked OK, so you shouldn't
730
+ # need to use this command unless for some reason you need to change
731
+ # your mind prior to the next confirmation. After any confirmation, Selenium will resume using the
732
+ # default behavior for future confirmations, automatically returning
733
+ # true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each
734
+ # confirmation.
735
+ #
736
+ def choose_ok_on_next_confirmation()
737
+ do_command("chooseOkOnNextConfirmation", [])
738
+ end
739
+
740
+
741
+ # Instructs Selenium to return the specified answer string in response to
742
+ # the next JavaScript prompt [window.prompt()].
743
+ #
744
+ # 'answer' is the answer to give in response to the prompt pop-up
745
+ def answer_on_next_prompt(answer)
746
+ do_command("answerOnNextPrompt", [answer,])
747
+ end
748
+
749
+
750
+ # Simulates the user clicking the "back" button on their browser.
751
+ #
752
+ def go_back()
753
+ do_command("goBack", [])
754
+ end
755
+
756
+
757
+ # Simulates the user clicking the "Refresh" button on their browser.
758
+ #
759
+ def refresh()
760
+ do_command("refresh", [])
761
+ end
762
+
763
+
764
+ # Simulates the user clicking the "close" button in the titlebar of a popup
765
+ # window or tab.
766
+ #
767
+ def close()
768
+ do_command("close", [])
769
+ end
770
+
771
+
772
+ # Has an alert occurred?
773
+ #
774
+ #
775
+ # This function never throws an exception
776
+ #
777
+ #
778
+ #
779
+ def is_alert_present()
780
+ return get_boolean("isAlertPresent", [])
781
+ end
782
+
783
+
784
+ # Has a prompt occurred?
785
+ #
786
+ #
787
+ # This function never throws an exception
788
+ #
789
+ #
790
+ #
791
+ def is_prompt_present()
792
+ return get_boolean("isPromptPresent", [])
793
+ end
794
+
795
+
796
+ # Has confirm() been called?
797
+ #
798
+ #
799
+ # This function never throws an exception
800
+ #
801
+ #
802
+ #
803
+ def is_confirmation_present()
804
+ return get_boolean("isConfirmationPresent", [])
805
+ end
806
+
807
+
808
+ # Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
809
+ #
810
+ # Getting an alert has the same effect as manually clicking OK. If an
811
+ # alert is generated but you do not get/verify it, the next Selenium action
812
+ # will fail.
813
+ # NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
814
+ # dialog.
815
+ # NOTE: Selenium does NOT support JavaScript alerts that are generated in a
816
+ # page's onload() event handler. In this case a visible dialog WILL be
817
+ # generated and Selenium will hang until someone manually clicks OK.
818
+ #
819
+ #
820
+ def get_alert()
821
+ return get_string("getAlert", [])
822
+ end
823
+
824
+
825
+ # Retrieves the message of a JavaScript confirmation dialog generated during
826
+ # the previous action.
827
+ #
828
+ #
829
+ # By default, the confirm function will return true, having the same effect
830
+ # as manually clicking OK. This can be changed by prior execution of the
831
+ # chooseCancelOnNextConfirmation command. If an confirmation is generated
832
+ # but you do not get/verify it, the next Selenium action will fail.
833
+ #
834
+ #
835
+ # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
836
+ # dialog.
837
+ #
838
+ #
839
+ # NOTE: Selenium does NOT support JavaScript confirmations that are
840
+ # generated in a page's onload() event handler. In this case a visible
841
+ # dialog WILL be generated and Selenium will hang until you manually click
842
+ # OK.
843
+ #
844
+ #
845
+ #
846
+ def get_confirmation()
847
+ return get_string("getConfirmation", [])
848
+ end
849
+
850
+
851
+ # Retrieves the message of a JavaScript question prompt dialog generated during
852
+ # the previous action.
853
+ #
854
+ # Successful handling of the prompt requires prior execution of the
855
+ # answerOnNextPrompt command. If a prompt is generated but you
856
+ # do not get/verify it, the next Selenium action will fail.
857
+ # NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
858
+ # dialog.
859
+ # NOTE: Selenium does NOT support JavaScript prompts that are generated in a
860
+ # page's onload() event handler. In this case a visible dialog WILL be
861
+ # generated and Selenium will hang until someone manually clicks OK.
862
+ #
863
+ #
864
+ def get_prompt()
865
+ return get_string("getPrompt", [])
866
+ end
867
+
868
+
869
+ # Gets the absolute URL of the current page.
870
+ #
871
+ def get_location()
872
+ return get_string("getLocation", [])
873
+ end
874
+
875
+
876
+ # Gets the title of the current page.
877
+ #
878
+ def get_title()
879
+ return get_string("getTitle", [])
880
+ end
881
+
882
+
883
+ # Gets the entire text of the page.
884
+ #
885
+ def get_body_text()
886
+ return get_string("getBodyText", [])
887
+ end
888
+
889
+
890
+ # Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
891
+ # For checkbox/radio elements, the value will be "on" or "off" depending on
892
+ # whether the element is checked or not.
893
+ #
894
+ # 'locator' is an element locator
895
+ def get_value(locator)
896
+ return get_string("getValue", [locator,])
897
+ end
898
+
899
+
900
+ # Gets the text of an element. This works for any element that contains
901
+ # text. This command uses either the textContent (Mozilla-like browsers) or
902
+ # the innerText (IE-like browsers) of the element, which is the rendered
903
+ # text shown to the user.
904
+ #
905
+ # 'locator' is an element locator
906
+ def get_text(locator)
907
+ return get_string("getText", [locator,])
908
+ end
909
+
910
+
911
+ # Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
912
+ #
913
+ # 'locator' is an element locator
914
+ def highlight(locator)
915
+ do_command("highlight", [locator,])
916
+ end
917
+
918
+
919
+ # Gets the result of evaluating the specified JavaScript snippet. The snippet may
920
+ # have multiple lines, but only the result of the last line will be returned.
921
+ #
922
+ # Note that, by default, the snippet will run in the context of the "selenium"
923
+ # object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
924
+ # refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
925
+ # If you need to use
926
+ # a locator to refer to a single element in your application page, you can
927
+ # use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
928
+ #
929
+ #
930
+ # 'script' is the JavaScript snippet to run
931
+ def get_eval(script)
932
+ return get_string("getEval", [script,])
933
+ end
934
+
935
+
936
+ # Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
937
+ #
938
+ # 'locator' is an element locator pointing to a checkbox or radio button
939
+ def is_checked(locator)
940
+ return get_boolean("isChecked", [locator,])
941
+ end
942
+
943
+
944
+ # Gets the text from a cell of a table. The cellAddress syntax
945
+ # tableLocator.row.column, where row and column start at 0.
946
+ #
947
+ # 'tableCellAddress' is a cell address, e.g. "foo.1.4"
948
+ def get_table(tableCellAddress)
949
+ return get_string("getTable", [tableCellAddress,])
950
+ end
951
+
952
+
953
+ # Gets all option labels (visible text) for selected options in the specified select or multi-select element.
954
+ #
955
+ # 'selectLocator' is an element locator identifying a drop-down menu
956
+ def get_selected_labels(selectLocator)
957
+ return get_string_array("getSelectedLabels", [selectLocator,])
958
+ end
959
+
960
+
961
+ # Gets option label (visible text) for selected option in the specified select element.
962
+ #
963
+ # 'selectLocator' is an element locator identifying a drop-down menu
964
+ def get_selected_label(selectLocator)
965
+ return get_string("getSelectedLabel", [selectLocator,])
966
+ end
967
+
968
+
969
+ # Gets all option values (value attributes) for selected options in the specified select or multi-select element.
970
+ #
971
+ # 'selectLocator' is an element locator identifying a drop-down menu
972
+ def get_selected_values(selectLocator)
973
+ return get_string_array("getSelectedValues", [selectLocator,])
974
+ end
975
+
976
+
977
+ # Gets option value (value attribute) for selected option in the specified select element.
978
+ #
979
+ # 'selectLocator' is an element locator identifying a drop-down menu
980
+ def get_selected_value(selectLocator)
981
+ return get_string("getSelectedValue", [selectLocator,])
982
+ end
983
+
984
+
985
+ # Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
986
+ #
987
+ # 'selectLocator' is an element locator identifying a drop-down menu
988
+ def get_selected_indexes(selectLocator)
989
+ return get_string_array("getSelectedIndexes", [selectLocator,])
990
+ end
991
+
992
+
993
+ # Gets option index (option number, starting at 0) for selected option in the specified select element.
994
+ #
995
+ # 'selectLocator' is an element locator identifying a drop-down menu
996
+ def get_selected_index(selectLocator)
997
+ return get_string("getSelectedIndex", [selectLocator,])
998
+ end
999
+
1000
+
1001
+ # Gets all option element IDs for selected options in the specified select or multi-select element.
1002
+ #
1003
+ # 'selectLocator' is an element locator identifying a drop-down menu
1004
+ def get_selected_ids(selectLocator)
1005
+ return get_string_array("getSelectedIds", [selectLocator,])
1006
+ end
1007
+
1008
+
1009
+ # Gets option element ID for selected option in the specified select element.
1010
+ #
1011
+ # 'selectLocator' is an element locator identifying a drop-down menu
1012
+ def get_selected_id(selectLocator)
1013
+ return get_string("getSelectedId", [selectLocator,])
1014
+ end
1015
+
1016
+
1017
+ # Determines whether some option in a drop-down menu is selected.
1018
+ #
1019
+ # 'selectLocator' is an element locator identifying a drop-down menu
1020
+ def is_something_selected(selectLocator)
1021
+ return get_boolean("isSomethingSelected", [selectLocator,])
1022
+ end
1023
+
1024
+
1025
+ # Gets all option labels in the specified select drop-down.
1026
+ #
1027
+ # 'selectLocator' is an element locator identifying a drop-down menu
1028
+ def get_select_options(selectLocator)
1029
+ return get_string_array("getSelectOptions", [selectLocator,])
1030
+ end
1031
+
1032
+
1033
+ # Gets the value of an element attribute.
1034
+ #
1035
+ # 'attributeLocator' is an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"
1036
+ def get_attribute(attributeLocator)
1037
+ return get_string("getAttribute", [attributeLocator,])
1038
+ end
1039
+
1040
+
1041
+ # Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
1042
+ #
1043
+ # 'pattern' is a pattern to match with the text of the page
1044
+ def is_text_present(pattern)
1045
+ return get_boolean("isTextPresent", [pattern,])
1046
+ end
1047
+
1048
+
1049
+ # Verifies that the specified element is somewhere on the page.
1050
+ #
1051
+ # 'locator' is an element locator
1052
+ def is_element_present(locator)
1053
+ return get_boolean("isElementPresent", [locator,])
1054
+ end
1055
+
1056
+
1057
+ # Determines if the specified element is visible. An
1058
+ # element can be rendered invisible by setting the CSS "visibility"
1059
+ # property to "hidden", or the "display" property to "none", either for the
1060
+ # element itself or one if its ancestors. This method will fail if
1061
+ # the element is not present.
1062
+ #
1063
+ # 'locator' is an element locator
1064
+ def is_visible(locator)
1065
+ return get_boolean("isVisible", [locator,])
1066
+ end
1067
+
1068
+
1069
+ # Determines whether the specified input element is editable, ie hasn't been disabled.
1070
+ # This method will fail if the specified element isn't an input element.
1071
+ #
1072
+ # 'locator' is an element locator
1073
+ def is_editable(locator)
1074
+ return get_boolean("isEditable", [locator,])
1075
+ end
1076
+
1077
+
1078
+ # Returns the IDs of all buttons on the page.
1079
+ #
1080
+ # If a given button has no ID, it will appear as "" in this array.
1081
+ #
1082
+ #
1083
+ def get_all_buttons()
1084
+ return get_string_array("getAllButtons", [])
1085
+ end
1086
+
1087
+
1088
+ # Returns the IDs of all links on the page.
1089
+ #
1090
+ # If a given link has no ID, it will appear as "" in this array.
1091
+ #
1092
+ #
1093
+ def get_all_links()
1094
+ return get_string_array("getAllLinks", [])
1095
+ end
1096
+
1097
+
1098
+ # Returns the IDs of all input fields on the page.
1099
+ #
1100
+ # If a given field has no ID, it will appear as "" in this array.
1101
+ #
1102
+ #
1103
+ def get_all_fields()
1104
+ return get_string_array("getAllFields", [])
1105
+ end
1106
+
1107
+
1108
+ # Returns every instance of some attribute from all known windows.
1109
+ #
1110
+ # 'attributeName' is name of an attribute on the windows
1111
+ def get_attribute_from_all_windows(attributeName)
1112
+ return get_string_array("getAttributeFromAllWindows", [attributeName,])
1113
+ end
1114
+
1115
+
1116
+ # deprecated - use dragAndDrop instead
1117
+ #
1118
+ # 'locator' is an element locator
1119
+ # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1120
+ def dragdrop(locator,movementsString)
1121
+ do_command("dragdrop", [locator,movementsString,])
1122
+ end
1123
+
1124
+
1125
+ # Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
1126
+ # Setting this value to 0 means that we'll send a "mousemove" event to every single pixel
1127
+ # in between the start location and the end location; that can be very slow, and may
1128
+ # cause some browsers to force the JavaScript to timeout.
1129
+ # If the mouse speed is greater than the distance between the two dragged objects, we'll
1130
+ # just send one "mousemove" at the start location and then one final one at the end location.
1131
+ #
1132
+ #
1133
+ # 'pixels' is the number of pixels between "mousemove" events
1134
+ def set_mouse_speed(pixels)
1135
+ do_command("setMouseSpeed", [pixels,])
1136
+ end
1137
+
1138
+
1139
+ # Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
1140
+ #
1141
+ def get_mouse_speed()
1142
+ return get_number("getMouseSpeed", [])
1143
+ end
1144
+
1145
+
1146
+ # Drags an element a certain distance and then drops it
1147
+ #
1148
+ # 'locator' is an element locator
1149
+ # 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
1150
+ def drag_and_drop(locator,movementsString)
1151
+ do_command("dragAndDrop", [locator,movementsString,])
1152
+ end
1153
+
1154
+
1155
+ # Drags an element and drops it on another element
1156
+ #
1157
+ # 'locatorOfObjectToBeDragged' is an element to be dragged
1158
+ # 'locatorOfDragDestinationObject' is an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
1159
+ def drag_and_drop_to_object(locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
1160
+ do_command("dragAndDropToObject", [locatorOfObjectToBeDragged,locatorOfDragDestinationObject,])
1161
+ end
1162
+
1163
+
1164
+ # Gives focus to the currently selected window
1165
+ #
1166
+ def window_focus()
1167
+ do_command("windowFocus", [])
1168
+ end
1169
+
1170
+
1171
+ # Resize currently selected window to take up the entire screen
1172
+ #
1173
+ def window_maximize()
1174
+ do_command("windowMaximize", [])
1175
+ end
1176
+
1177
+
1178
+ # Returns the IDs of all windows that the browser knows about.
1179
+ #
1180
+ def get_all_window_ids()
1181
+ return get_string_array("getAllWindowIds", [])
1182
+ end
1183
+
1184
+
1185
+ # Returns the names of all windows that the browser knows about.
1186
+ #
1187
+ def get_all_window_names()
1188
+ return get_string_array("getAllWindowNames", [])
1189
+ end
1190
+
1191
+
1192
+ # Returns the titles of all windows that the browser knows about.
1193
+ #
1194
+ def get_all_window_titles()
1195
+ return get_string_array("getAllWindowTitles", [])
1196
+ end
1197
+
1198
+
1199
+ # Returns the entire HTML source between the opening and
1200
+ # closing "html" tags.
1201
+ #
1202
+ def get_html_source()
1203
+ return get_string("getHtmlSource", [])
1204
+ end
1205
+
1206
+
1207
+ # Moves the text cursor to the specified position in the given input element or textarea.
1208
+ # This method will fail if the specified element isn't an input element or textarea.
1209
+ #
1210
+ # 'locator' is an element locator pointing to an input element or textarea
1211
+ # '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.
1212
+ def set_cursor_position(locator,position)
1213
+ do_command("setCursorPosition", [locator,position,])
1214
+ end
1215
+
1216
+
1217
+ # Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
1218
+ # will be ignored.
1219
+ #
1220
+ # 'locator' is an element locator pointing to an element
1221
+ def get_element_index(locator)
1222
+ return get_number("getElementIndex", [locator,])
1223
+ end
1224
+
1225
+
1226
+ # Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will
1227
+ # not be considered ordered.
1228
+ #
1229
+ # 'locator1' is an element locator pointing to the first element
1230
+ # 'locator2' is an element locator pointing to the second element
1231
+ def is_ordered(locator1,locator2)
1232
+ return get_boolean("isOrdered", [locator1,locator2,])
1233
+ end
1234
+
1235
+
1236
+ # Retrieves the horizontal position of an element
1237
+ #
1238
+ # 'locator' is an element locator pointing to an element OR an element itself
1239
+ def get_element_position_left(locator)
1240
+ return get_number("getElementPositionLeft", [locator,])
1241
+ end
1242
+
1243
+
1244
+ # Retrieves the vertical position of an element
1245
+ #
1246
+ # 'locator' is an element locator pointing to an element OR an element itself
1247
+ def get_element_position_top(locator)
1248
+ return get_number("getElementPositionTop", [locator,])
1249
+ end
1250
+
1251
+
1252
+ # Retrieves the width of an element
1253
+ #
1254
+ # 'locator' is an element locator pointing to an element
1255
+ def get_element_width(locator)
1256
+ return get_number("getElementWidth", [locator,])
1257
+ end
1258
+
1259
+
1260
+ # Retrieves the height of an element
1261
+ #
1262
+ # 'locator' is an element locator pointing to an element
1263
+ def get_element_height(locator)
1264
+ return get_number("getElementHeight", [locator,])
1265
+ end
1266
+
1267
+
1268
+ # Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
1269
+ #
1270
+ # Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
1271
+ # 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.
1272
+ #
1273
+ # This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
1274
+ #
1275
+ # 'locator' is an element locator pointing to an input element or textarea
1276
+ def get_cursor_position(locator)
1277
+ return get_number("getCursorPosition", [locator,])
1278
+ end
1279
+
1280
+
1281
+ # Returns the specified expression.
1282
+ #
1283
+ # This is useful because of JavaScript preprocessing.
1284
+ # It is used to generate commands like assertExpression and waitForExpression.
1285
+ #
1286
+ #
1287
+ # 'expression' is the value to return
1288
+ def get_expression(expression)
1289
+ return get_string("getExpression", [expression,])
1290
+ end
1291
+
1292
+
1293
+ # Returns the number of nodes that match the specified xpath, eg. "//table" would give
1294
+ # the number of tables.
1295
+ #
1296
+ # 'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
1297
+ def get_xpath_count(xpath)
1298
+ return get_number("getXpathCount", [xpath,])
1299
+ end
1300
+
1301
+
1302
+ # Temporarily sets the "id" attribute of the specified element, so you can locate it in the future
1303
+ # using its ID rather than a slow/complicated XPath. This ID will disappear once the page is
1304
+ # reloaded.
1305
+ #
1306
+ # 'locator' is an element locator pointing to an element
1307
+ # 'identifier' is a string to be used as the ID of the specified element
1308
+ def assign_id(locator,identifier)
1309
+ do_command("assignId", [locator,identifier,])
1310
+ end
1311
+
1312
+
1313
+ # Specifies whether Selenium should use the native in-browser implementation
1314
+ # of XPath (if any native version is available); if you pass "false" to
1315
+ # this function, we will always use our pure-JavaScript xpath library.
1316
+ # Using the pure-JS xpath library can improve the consistency of xpath
1317
+ # element locators between different browser vendors, but the pure-JS
1318
+ # version is much slower than the native implementations.
1319
+ #
1320
+ # 'allow' is boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
1321
+ def allow_native_xpath(allow)
1322
+ do_command("allowNativeXpath", [allow,])
1323
+ end
1324
+
1325
+
1326
+ # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
1327
+ # The snippet may have multiple lines, but only the result of the last line
1328
+ # will be considered.
1329
+ #
1330
+ # Note that, by default, the snippet will be run in the runner's test window, not in the window
1331
+ # of your application. To get the window of your application, you can use
1332
+ # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
1333
+ # run your JavaScript in there
1334
+ #
1335
+ #
1336
+ # 'script' is the JavaScript snippet to run
1337
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1338
+ def wait_for_condition(script,timeout)
1339
+ do_command("waitForCondition", [script,timeout,])
1340
+ end
1341
+
1342
+
1343
+ # Specifies the amount of time that Selenium will wait for actions to complete.
1344
+ #
1345
+ # Actions that require waiting include "open" and the "waitFor*" actions.
1346
+ #
1347
+ # The default timeout is 30 seconds.
1348
+ #
1349
+ # 'timeout' is a timeout in milliseconds, after which the action will return with an error
1350
+ def set_timeout(timeout)
1351
+ do_command("setTimeout", [timeout,])
1352
+ end
1353
+
1354
+
1355
+ # Waits for a new page to load.
1356
+ #
1357
+ # You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
1358
+ # (which are only available in the JS API).
1359
+ # Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
1360
+ # flag when it first notices a page load. Running any other Selenium command after
1361
+ # turns the flag to false. Hence, if you want to wait for a page to load, you must
1362
+ # wait immediately after a Selenium command that caused a page-load.
1363
+ #
1364
+ #
1365
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1366
+ def wait_for_page_to_load(timeout)
1367
+ do_command("waitForPageToLoad", [timeout,])
1368
+ end
1369
+
1370
+
1371
+ # Waits for a new frame to load.
1372
+ #
1373
+ # Selenium constantly keeps track of new pages and frames loading,
1374
+ # and sets a "newPageLoaded" flag when it first notices a page load.
1375
+ #
1376
+ #
1377
+ # See waitForPageToLoad for more information.
1378
+ #
1379
+ # 'frameAddress' is FrameAddress from the server side
1380
+ # 'timeout' is a timeout in milliseconds, after which this command will return with an error
1381
+ def wait_for_frame_to_load(frameAddress,timeout)
1382
+ do_command("waitForFrameToLoad", [frameAddress,timeout,])
1383
+ end
1384
+
1385
+
1386
+ # Return all cookies of the current page under test.
1387
+ #
1388
+ def get_cookie()
1389
+ return get_string("getCookie", [])
1390
+ end
1391
+
1392
+
1393
+ # Create a new cookie whose path and domain are same with those of current page
1394
+ # under test, unless you specified a path for this cookie explicitly.
1395
+ #
1396
+ # 'nameValuePair' is name and value of the cookie in a format "name=value"
1397
+ # 'optionsString' is options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
1398
+ def create_cookie(nameValuePair,optionsString)
1399
+ do_command("createCookie", [nameValuePair,optionsString,])
1400
+ end
1401
+
1402
+
1403
+ # Delete a named cookie with specified path.
1404
+ #
1405
+ # 'name' is the name of the cookie to be deleted
1406
+ # 'path' is the path property of the cookie to be deleted
1407
+ def delete_cookie(name,path)
1408
+ do_command("deleteCookie", [name,path,])
1409
+ end
1410
+
1411
+
1412
+ # Sets the threshold for browser-side logging messages; log messages beneath this threshold will be discarded.
1413
+ # Valid logLevel strings are: "debug", "info", "warn", "error" or "off".
1414
+ # To see the browser logs, you need to
1415
+ # either show the log window in GUI mode, or enable browser-side logging in Selenium RC.
1416
+ #
1417
+ # 'logLevel' is one of the following: "debug", "info", "warn", "error" or "off"
1418
+ def set_browser_log_level(logLevel)
1419
+ do_command("setBrowserLogLevel", [logLevel,])
1420
+ end
1421
+
1422
+
1423
+ # Creates a new "script" tag in the body of the current test window, and
1424
+ # adds the specified text into the body of the command. Scripts run in
1425
+ # this way can often be debugged more easily than scripts executed using
1426
+ # Selenium's "getEval" command. Beware that JS exceptions thrown in these script
1427
+ # tags aren't managed by Selenium, so you should probably wrap your script
1428
+ # in try/catch blocks if there is any chance that the script will throw
1429
+ # an exception.
1430
+ #
1431
+ # 'script' is the JavaScript snippet to run
1432
+ def run_script(script)
1433
+ do_command("runScript", [script,])
1434
+ end
1435
+
1436
+
1437
+ # Defines a new function for Selenium to locate elements on the page.
1438
+ # For example,
1439
+ # if you define the strategy "foo", and someone runs click("foo=blah"), we'll
1440
+ # run your function, passing you the string "blah", and click on the element
1441
+ # that your function
1442
+ # returns, or throw an "Element not found" error if your function returns null.
1443
+ #
1444
+ # We'll pass three arguments to your function:
1445
+ # * locator: the string the user passed in
1446
+ # * inWindow: the currently selected window
1447
+ # * inDocument: the currently selected document
1448
+ #
1449
+ #
1450
+ # The function must return null if the element can't be found.
1451
+ #
1452
+ # 'strategyName' is the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation.
1453
+ # 'functionDefinition' is a string defining the body of a function in JavaScript. For example: <tt>return inDocument.getElementById(locator);</tt>
1454
+ def add_location_strategy(strategyName,functionDefinition)
1455
+ do_command("addLocationStrategy", [strategyName,functionDefinition,])
1456
+ end
1457
+
1458
+
1459
+ # Writes a message to the status bar and adds a note to the browser-side
1460
+ # log.
1461
+ #
1462
+ # 'context' is the message to be sent to the browser
1463
+ def set_context(context)
1464
+ do_command("setContext", [context,])
1465
+ end
1466
+
1467
+
1468
+ # Captures a PNG screenshot to the specified file.
1469
+ #
1470
+ # 'filename' is the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"
1471
+ def capture_screenshot(filename)
1472
+ do_command("captureScreenshot", [filename,])
1473
+ end
1474
+
1317
1475
 
1318
1476
  end
1319
1477
 
@@ -1322,13 +1480,6 @@ module Selenium
1322
1480
  end
1323
1481
 
1324
1482
  class SeleniumCommandError < RuntimeError
1325
- def initialize(command_string)
1326
- @command_string = command_string
1327
- end
1328
-
1329
- def to_s
1330
- super + "(command=#{@command_string})"
1331
- end
1332
1483
  end
1333
1484
 
1334
1485
  # Defines a mixin module that you can use to write Selenium tests