Module selenium
[hide private]
[frames] | no frames]

Source Code for Module selenium

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