Selenium 1.0.4 → 1.0.9

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