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