/testing/selenium-core/scripts/selenium-api.js
JavaScript | 3043 lines | 1457 code | 245 blank | 1341 comment | 286 complexity | 8e962db41a4337f77b196d02a4f6462d MD5 | raw file
Large files files are truncated, but you can click here to view the full file
1/* 2 * Copyright 2004 ThoughtWorks, Inc 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18// TODO: stop navigating this.browserbot.document() ... it breaks encapsulation 19 20var storedVars = new Object(); 21 22function Selenium(browserbot) { 23 /** 24 * Defines an object that runs Selenium commands. 25 * 26 * <h3><a name="locators"></a>Element Locators</h3> 27 * <p> 28 * Element Locators tell Selenium which HTML element a command refers to. 29 * The format of a locator is:</p> 30 * <blockquote> 31 * <em>locatorType</em><strong>=</strong><em>argument</em> 32 * </blockquote> 33 * 34 * <p> 35 * We support the following strategies for locating elements: 36 * </p> 37 * 38 * <ul> 39 * <li><strong>identifier</strong>=<em>id</em>: 40 * Select the element with the specified @id attribute. If no match is 41 * found, select the first element whose @name attribute is <em>id</em>. 42 * (This is normally the default; see below.)</li> 43 * <li><strong>id</strong>=<em>id</em>: 44 * Select the element with the specified @id attribute.</li> 45 * 46 * <li><strong>name</strong>=<em>name</em>: 47 * Select the first element with the specified @name attribute. 48 * <ul class="first last simple"> 49 * <li>username</li> 50 * <li>name=username</li> 51 * </ul> 52 * 53 * <p>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</p> 54 * 55 * <ul class="first last simple"> 56 * <li>name=flavour value=chocolate</li> 57 * </ul> 58 * </li> 59 * <li><strong>dom</strong>=<em>javascriptExpression</em>: 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 * <ul class="first last simple"> 64 * <li>dom=document.forms['myForm'].myDropdown</li> 65 * <li>dom=document.images[56]</li> 66 * <li>dom=function foo() { return document.links[1]; }; foo();</li> 67 * </ul> 68 * 69 * </li> 70 * 71 * <li><strong>xpath</strong>=<em>xpathExpression</em>: 72 * Locate an element using an XPath expression. 73 * <ul class="first last simple"> 74 * <li>xpath=//img[@alt='The image alt text']</li> 75 * <li>xpath=//table[@id='table1']//tr[4]/td[2]</li> 76 * <li>xpath=//a[contains(@href,'#id1')]</li> 77 * <li>xpath=//a[contains(@href,'#id1')]/@class</li> 78 * <li>xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td</li> 79 * <li>xpath=//input[@name='name2' and @value='yes']</li> 80 * <li>xpath=//*[text()="right"]</li> 81 * 82 * </ul> 83 * </li> 84 * <li><strong>link</strong>=<em>textPattern</em>: 85 * Select the link (anchor) element which contains text matching the 86 * specified <em>pattern</em>. 87 * <ul class="first last simple"> 88 * <li>link=The link text</li> 89 * </ul> 90 * 91 * </li> 92 * 93 * <li><strong>css</strong>=<em>cssSelectorSyntax</em>: 94 * Select the element using css selectors. Please refer to <a href="http://www.w3.org/TR/REC-CSS2/selector.html">CSS2 selectors</a>, <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/">CSS3 selectors</a> 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. 95 * <ul class="first last simple"> 96 * <li>css=a[href="#id3"]</li> 97 * <li>css=span#firstChild + span</li> 98 * </ul> 99 * <p>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). </p> 100 * </li> 101 * 102 * <li><strong>ui</strong>=<em>uiSpecifierString</em>: 103 * Locate an element by resolving the UI specifier string to another locator, and evaluating it. See the <a href="http://svn.openqa.org/fisheye/browse/~raw,r=trunk/selenium/trunk/src/main/resources/core/scripts/ui-doc.html">Selenium UI-Element Reference</a> for more details. 104 * <ul class="first last simple"> 105 * <li>ui=loginPages::loginButton()</li> 106 * <li>ui=settingsPages::toggle(label=Hide Email)</li> 107 * <li>ui=forumPages::postBody(index=2)//a[2]</li> 108 * </ul> 109 * </li> 110 * 111 * </ul> 112 * 113 * <p> 114 * Without an explicit locator prefix, Selenium uses the following default 115 * strategies: 116 * </p> 117 * 118 * <ul class="simple"> 119 * <li><strong>dom</strong>, for locators starting with "document."</li> 120 * <li><strong>xpath</strong>, for locators starting with "//"</li> 121 * <li><strong>identifier</strong>, otherwise</li> 122 * </ul> 123 * 124 * <h3><a name="element-filters">Element Filters</a></h3> 125 * <blockquote> 126 * <p>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.</p> 127 * <p>Filters look much like locators, ie.</p> 128 * <blockquote> 129 * <em>filterType</em><strong>=</strong><em>argument</em></blockquote> 130 * 131 * <p>Supported element-filters are:</p> 132 * <p><strong>value=</strong><em>valuePattern</em></p> 133 * <blockquote> 134 * Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote> 135 * <p><strong>index=</strong><em>index</em></p> 136 * <blockquote> 137 * Selects a single element based on its position in the list (offset from zero).</blockquote> 138 * </blockquote> 139 * 140 * <h3><a name="patterns"></a>String-match Patterns</h3> 141 * 142 * <p> 143 * Various Pattern syntaxes are available for matching string values: 144 * </p> 145 * <ul> 146 * <li><strong>glob:</strong><em>pattern</em>: 147 * Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a 148 * kind of limited regular-expression syntax typically used in command-line 149 * shells. In a glob pattern, "*" represents any sequence of characters, and "?" 150 * represents any single character. Glob patterns match against the entire 151 * string.</li> 152 * <li><strong>regexp:</strong><em>regexp</em>: 153 * Match a string using a regular-expression. The full power of JavaScript 154 * regular-expressions is available.</li> 155 * <li><strong>regexpi:</strong><em>regexpi</em>: 156 * Match a string using a case-insensitive regular-expression.</li> 157 * <li><strong>exact:</strong><em>string</em>: 158 * 159 * Match a string exactly, verbatim, without any of that fancy wildcard 160 * stuff.</li> 161 * </ul> 162 * <p> 163 * If no pattern prefix is specified, Selenium assumes that it's a "glob" 164 * pattern. 165 * </p> 166 * <p> 167 * For commands that return multiple values (such as verifySelectOptions), 168 * the string being matched is a comma-separated list of the return values, 169 * where both commas and backslashes in the values are backslash-escaped. 170 * When providing a pattern, the optional matching syntax (i.e. glob, 171 * regexp, etc.) is specified once, as usual, at the beginning of the 172 * pattern. 173 * </p> 174 */ 175 this.browserbot = browserbot; 176 this.optionLocatorFactory = new OptionLocatorFactory(); 177 // DGF for backwards compatibility 178 this.page = function() { 179 return browserbot; 180 }; 181 this.defaultTimeout = Selenium.DEFAULT_TIMEOUT; 182 this.mouseSpeed = 10; 183} 184 185Selenium.DEFAULT_TIMEOUT = 30 * 1000; 186Selenium.DEFAULT_MOUSE_SPEED = 10; 187Selenium.RIGHT_MOUSE_CLICK = 2; 188 189Selenium.decorateFunctionWithTimeout = function(f, timeout) { 190 if (f == null) { 191 return null; 192 } 193 var timeoutValue = parseInt(timeout); 194 if (isNaN(timeoutValue)) { 195 throw new SeleniumError("Timeout is not a number: '" + timeout + "'"); 196 } 197 var now = new Date().getTime(); 198 var timeoutTime = now + timeoutValue; 199 return function() { 200 if (new Date().getTime() > timeoutTime) { 201 throw new SeleniumError("Timed out after " + timeoutValue + "ms"); 202 } 203 return f(); 204 }; 205} 206 207Selenium.createForWindow = function(window, proxyInjectionMode) { 208 if (!window.location) { 209 throw "error: not a window!"; 210 } 211 return new Selenium(BrowserBot.createForWindow(window, proxyInjectionMode)); 212}; 213 214Selenium.prototype.reset = function() { 215 this.defaultTimeout = Selenium.DEFAULT_TIMEOUT; 216 // todo: this.browserbot.reset() 217 this.browserbot.selectWindow("null"); 218 this.browserbot.resetPopups(); 219}; 220 221Selenium.prototype.doClick = function(locator) { 222 /** 223 * Clicks on a link, button, checkbox or radio button. If the click action 224 * causes a new page to load (like a link usually does), call 225 * waitForPageToLoad. 226 * 227 * @param locator an element locator 228 * 229 */ 230 var element = this.browserbot.findElement(locator); 231 this.browserbot.clickElement(element); 232}; 233 234Selenium.prototype.doDoubleClick = function(locator) { 235 /** 236 * Double clicks on a link, button, checkbox or radio button. If the double click action 237 * causes a new page to load (like a link usually does), call 238 * waitForPageToLoad. 239 * 240 * @param locator an element locator 241 * 242 */ 243 var element = this.browserbot.findElement(locator); 244 this.browserbot.doubleClickElement(element); 245}; 246 247Selenium.prototype.doContextMenu = function(locator) { 248 /** 249 * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element). 250 * 251 * @param locator an element locator 252 * 253 */ 254 var element = this.browserbot.findElement(locator); 255 this.browserbot.contextMenuOnElement(element); 256}; 257 258Selenium.prototype.doClickAt = function(locator, coordString) { 259 /** 260 * Clicks on a link, button, checkbox or radio button. If the click action 261 * causes a new page to load (like a link usually does), call 262 * waitForPageToLoad. 263 * 264 * @param locator an element locator 265 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 266 * event relative to the element returned by the locator. 267 * 268 */ 269 var element = this.browserbot.findElement(locator); 270 var clientXY = getClientXY(element, coordString) 271 this.doMouseMove(locator); 272 this.doMouseDown(locator); 273 this.browserbot.clickElement(element, clientXY[0], clientXY[1]); 274 this.doMouseUp(locator); 275}; 276 277Selenium.prototype.doDoubleClickAt = function(locator, coordString) { 278 /** 279 * Doubleclicks on a link, button, checkbox or radio button. If the action 280 * causes a new page to load (like a link usually does), call 281 * waitForPageToLoad. 282 * 283 * @param locator an element locator 284 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 285 * event relative to the element returned by the locator. 286 * 287 */ 288 var element = this.browserbot.findElement(locator); 289 var clientXY = getClientXY(element, coordString) 290 this.doMouseMove(locator); 291 this.doMouseDown(locator); 292 this.browserbot.doubleClickElement(element, clientXY[0], clientXY[1]); 293 this.doMouseUp(locator); 294}; 295 296Selenium.prototype.doContextMenuAt = function(locator, coordString) { 297 /** 298 * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element). 299 * 300 * @param locator an element locator 301 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 302 * event relative to the element returned by the locator. 303 * 304 */ 305 var element = this.browserbot.findElement(locator); 306 var clientXY = getClientXY(element, coordString) 307 this.browserbot.contextMenuOnElement(element, clientXY[0], clientXY[1]); 308}; 309 310Selenium.prototype.doFireEvent = function(locator, eventName) { 311 /** 312 * Explicitly simulate an event, to trigger the corresponding "on<em>event</em>" 313 * handler. 314 * 315 * @param locator an <a href="#locators">element locator</a> 316 * @param eventName the event name, e.g. "focus" or "blur" 317 */ 318 var element = this.browserbot.findElement(locator); 319 triggerEvent(element, eventName, false); 320}; 321 322Selenium.prototype.doFocus = function(locator) { 323 /** Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field. 324 * 325 * @param locator an <a href="#locators">element locator</a> 326 */ 327 var element = this.browserbot.findElement(locator); 328 if (element.focus) { 329 element.focus(); 330 } else { 331 triggerEvent(element, "focus", false); 332 } 333} 334 335Selenium.prototype.doKeyPress = function(locator, keySequence) { 336 /** 337 * Simulates a user pressing and releasing a key. 338 * 339 * @param locator an <a href="#locators">element locator</a> 340 * @param keySequence Either be a string("\" followed by the numeric keycode 341 * of the key to be pressed, normally the ASCII value of that key), or a single 342 * character. For example: "w", "\119". 343 */ 344 var element = this.browserbot.findElement(locator); 345 triggerKeyEvent(element, 'keypress', keySequence, true, 346 this.browserbot.controlKeyDown, 347 this.browserbot.altKeyDown, 348 this.browserbot.shiftKeyDown, 349 this.browserbot.metaKeyDown); 350}; 351 352Selenium.prototype.doShiftKeyDown = function() { 353 /** 354 * Press the shift key and hold it down until doShiftUp() is called or a new page is loaded. 355 * 356 */ 357 this.browserbot.shiftKeyDown = true; 358}; 359 360Selenium.prototype.doShiftKeyUp = function() { 361 /** 362 * Release the shift key. 363 * 364 */ 365 this.browserbot.shiftKeyDown = false; 366}; 367 368Selenium.prototype.doMetaKeyDown = function() { 369 /** 370 * Press the meta key and hold it down until doMetaUp() is called or a new page is loaded. 371 * 372 */ 373 this.browserbot.metaKeyDown = true; 374}; 375 376Selenium.prototype.doMetaKeyUp = function() { 377 /** 378 * Release the meta key. 379 * 380 */ 381 this.browserbot.metaKeyDown = false; 382}; 383 384Selenium.prototype.doAltKeyDown = function() { 385 /** 386 * Press the alt key and hold it down until doAltUp() is called or a new page is loaded. 387 * 388 */ 389 this.browserbot.altKeyDown = true; 390}; 391 392Selenium.prototype.doAltKeyUp = function() { 393 /** 394 * Release the alt key. 395 * 396 */ 397 this.browserbot.altKeyDown = false; 398}; 399 400Selenium.prototype.doControlKeyDown = function() { 401 /** 402 * Press the control key and hold it down until doControlUp() is called or a new page is loaded. 403 * 404 */ 405 this.browserbot.controlKeyDown = true; 406}; 407 408Selenium.prototype.doControlKeyUp = function() { 409 /** 410 * Release the control key. 411 * 412 */ 413 this.browserbot.controlKeyDown = false; 414}; 415 416Selenium.prototype.doKeyDown = function(locator, keySequence) { 417 /** 418 * Simulates a user pressing a key (without releasing it yet). 419 * 420 * @param locator an <a href="#locators">element locator</a> 421 * @param keySequence Either be a string("\" followed by the numeric keycode 422 * of the key to be pressed, normally the ASCII value of that key), or a single 423 * character. For example: "w", "\119". 424 */ 425 var element = this.browserbot.findElement(locator); 426 triggerKeyEvent(element, 'keydown', keySequence, true, 427 this.browserbot.controlKeyDown, 428 this.browserbot.altKeyDown, 429 this.browserbot.shiftKeyDown, 430 this.browserbot.metaKeyDown); 431}; 432 433Selenium.prototype.doKeyUp = function(locator, keySequence) { 434 /** 435 * Simulates a user releasing a key. 436 * 437 * @param locator an <a href="#locators">element locator</a> 438 * @param keySequence Either be a string("\" followed by the numeric keycode 439 * of the key to be pressed, normally the ASCII value of that key), or a single 440 * character. For example: "w", "\119". 441 */ 442 var element = this.browserbot.findElement(locator); 443 triggerKeyEvent(element, 'keyup', keySequence, true, 444 this.browserbot.controlKeyDown, 445 this.browserbot.altKeyDown, 446 this.browserbot.shiftKeyDown, 447 this.browserbot.metaKeyDown); 448}; 449 450function getClientXY(element, coordString) { 451 // Parse coordString 452 var coords = null; 453 var x; 454 var y; 455 if (coordString) { 456 coords = coordString.split(/,/); 457 x = Number(coords[0]); 458 y = Number(coords[1]); 459 } 460 else { 461 x = y = 0; 462 } 463 464 // Get position of element, 465 // Return 2 item array with clientX and clientY 466 return [Selenium.prototype.getElementPositionLeft(element) + x, Selenium.prototype.getElementPositionTop(element) + y]; 467} 468 469Selenium.prototype.doMouseOver = function(locator) { 470 /** 471 * Simulates a user hovering a mouse over the specified element. 472 * 473 * @param locator an <a href="#locators">element locator</a> 474 */ 475 var element = this.browserbot.findElement(locator); 476 this.browserbot.triggerMouseEvent(element, 'mouseover', true); 477}; 478 479Selenium.prototype.doMouseOut = function(locator) { 480 /** 481 * Simulates a user moving the mouse pointer away from the specified element. 482 * 483 * @param locator an <a href="#locators">element locator</a> 484 */ 485 var element = this.browserbot.findElement(locator); 486 this.browserbot.triggerMouseEvent(element, 'mouseout', true); 487}; 488 489Selenium.prototype.doMouseDown = function(locator) { 490 /** 491 * Simulates a user pressing the left mouse button (without releasing it yet) on 492 * the specified element. 493 * 494 * @param locator an <a href="#locators">element locator</a> 495 */ 496 var element = this.browserbot.findElement(locator); 497 this.browserbot.triggerMouseEvent(element, 'mousedown', true); 498}; 499 500Selenium.prototype.doMouseDownRight = function(locator) { 501 /** 502 * Simulates a user pressing the right mouse button (without releasing it yet) on 503 * the specified element. 504 * 505 * @param locator an <a href="#locators">element locator</a> 506 */ 507 var element = this.browserbot.findElement(locator); 508 this.browserbot.triggerMouseEvent(element, 'mousedown', true, undefined, undefined, Selenium.RIGHT_MOUSE_CLICK); 509}; 510 511Selenium.prototype.doMouseDownAt = function(locator, coordString) { 512 /** 513 * Simulates a user pressing the left mouse button (without releasing it yet) at 514 * the specified location. 515 * 516 * @param locator an <a href="#locators">element locator</a> 517 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 518 * event relative to the element returned by the locator. 519 */ 520 var element = this.browserbot.findElement(locator); 521 var clientXY = getClientXY(element, coordString) 522 523 this.browserbot.triggerMouseEvent(element, 'mousedown', true, clientXY[0], clientXY[1]); 524}; 525 526Selenium.prototype.doMouseDownRightAt = function(locator, coordString) { 527 /** 528 * Simulates a user pressing the right mouse button (without releasing it yet) at 529 * the specified location. 530 * 531 * @param locator an <a href="#locators">element locator</a> 532 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 533 * event relative to the element returned by the locator. 534 */ 535 var element = this.browserbot.findElement(locator); 536 var clientXY = getClientXY(element, coordString) 537 538 this.browserbot.triggerMouseEvent(element, 'mousedown', true, clientXY[0], clientXY[1], Selenium.RIGHT_MOUSE_CLICK); 539}; 540 541Selenium.prototype.doMouseUp = function(locator) { 542 /** 543 * Simulates the event that occurs when the user releases the mouse button (i.e., stops 544 * holding the button down) on the specified element. 545 * 546 * @param locator an <a href="#locators">element locator</a> 547 */ 548 var element = this.browserbot.findElement(locator); 549 this.browserbot.triggerMouseEvent(element, 'mouseup', true); 550}; 551 552Selenium.prototype.doMouseUpRight = function(locator) { 553 /** 554 * Simulates the event that occurs when the user releases the right mouse button (i.e., stops 555 * holding the button down) on the specified element. 556 * 557 * @param locator an <a href="#locators">element locator</a> 558 */ 559 var element = this.browserbot.findElement(locator); 560 this.browserbot.triggerMouseEvent(element, 'mouseup', true, undefined, undefined, Selenium.RIGHT_MOUSE_CLICK); 561}; 562 563Selenium.prototype.doMouseUpAt = function(locator, coordString) { 564 /** 565 * Simulates the event that occurs when the user releases the mouse button (i.e., stops 566 * holding the button down) at the specified location. 567 * 568 * @param locator an <a href="#locators">element locator</a> 569 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 570 * event relative to the element returned by the locator. 571 */ 572 var element = this.browserbot.findElement(locator); 573 var clientXY = getClientXY(element, coordString) 574 575 this.browserbot.triggerMouseEvent(element, 'mouseup', true, clientXY[0], clientXY[1]); 576}; 577 578Selenium.prototype.doMouseUpRightAt = function(locator, coordString) { 579 /** 580 * Simulates the event that occurs when the user releases the right mouse button (i.e., stops 581 * holding the button down) at the specified location. 582 * 583 * @param locator an <a href="#locators">element locator</a> 584 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 585 * event relative to the element returned by the locator. 586 */ 587 var element = this.browserbot.findElement(locator); 588 var clientXY = getClientXY(element, coordString) 589 590 this.browserbot.triggerMouseEvent(element, 'mouseup', true, clientXY[0], clientXY[1], Selenium.RIGHT_MOUSE_CLICK); 591}; 592 593Selenium.prototype.doMouseMove = function(locator) { 594 /** 595 * Simulates a user pressing the mouse button (without releasing it yet) on 596 * the specified element. 597 * 598 * @param locator an <a href="#locators">element locator</a> 599 */ 600 var element = this.browserbot.findElement(locator); 601 this.browserbot.triggerMouseEvent(element, 'mousemove', true); 602}; 603 604Selenium.prototype.doMouseMoveAt = function(locator, coordString) { 605 /** 606 * Simulates a user pressing the mouse button (without releasing it yet) on 607 * the specified element. 608 * 609 * @param locator an <a href="#locators">element locator</a> 610 * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse 611 * event relative to the element returned by the locator. 612 */ 613 614 var element = this.browserbot.findElement(locator); 615 var clientXY = getClientXY(element, coordString) 616 617 this.browserbot.triggerMouseEvent(element, 'mousemove', true, clientXY[0], clientXY[1]); 618}; 619 620Selenium.prototype.doType = function(locator, value) { 621 /** 622 * Sets the value of an input field, as though you typed it in. 623 * 624 * <p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases, 625 * value should be the value of the option selected, not the visible text.</p> 626 * 627 * @param locator an <a href="#locators">element locator</a> 628 * @param value the value to type 629 */ 630 if (this.browserbot.controlKeyDown || this.browserbot.altKeyDown || this.browserbot.metaKeyDown) { 631 throw new SeleniumError("type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()"); 632 } 633 // TODO fail if it can't be typed into. 634 var element = this.browserbot.findElement(locator); 635 if (this.browserbot.shiftKeyDown) { 636 value = new String(value).toUpperCase(); 637 } 638 this.browserbot.replaceText(element, value); 639}; 640 641Selenium.prototype.doTypeKeys = function(locator, value) { 642 /** 643 * Simulates keystroke events on the specified element, as though you typed the value key-by-key. 644 * 645 * <p>This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string; 646 * this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.</p> 647 * 648 * <p>Unlike the simple "type" command, which forces the specified value into the page directly, this command 649 * may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. 650 * For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in 651 * the field.</p> 652 * <p>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 653 * send the keystroke events corresponding to what you just typed.</p> 654 * 655 * @param locator an <a href="#locators">element locator</a> 656 * @param value the value to type 657 */ 658 var keys = new String(value).split(""); 659 for (var i = 0; i < keys.length; i++) { 660 var c = keys[i]; 661 this.doKeyDown(locator, c); 662 this.doKeyUp(locator, c); 663 this.doKeyPress(locator, c); 664 } 665}; 666 667Selenium.prototype.doSetSpeed = function(value) { 668 /** 669 * 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., 670 * the delay is 0 milliseconds. 671 * 672 * @param value the number of milliseconds to pause after operation 673 */ 674 throw new SeleniumError("this operation is only implemented in selenium-rc, and should never result in a request making it across the wire"); 675}; 676 677Selenium.prototype.getSpeed = function() { 678 /** 679 * 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., 680 * the delay is 0 milliseconds. 681 * 682 * See also setSpeed. 683 * 684 * @return string the execution speed in milliseconds. 685 */ 686 throw new SeleniumError("this operation is only implemented in selenium-rc, and should never result in a request making it across the wire"); 687}; 688 689Selenium.prototype.findToggleButton = function(locator) { 690 var element = this.browserbot.findElement(locator); 691 if (element.checked == null) { 692 Assert.fail("Element " + locator + " is not a toggle-button."); 693 } 694 return element; 695} 696 697Selenium.prototype.doCheck = function(locator) { 698 /** 699 * Check a toggle-button (checkbox/radio) 700 * 701 * @param locator an <a href="#locators">element locator</a> 702 */ 703 this.findToggleButton(locator).checked = true; 704}; 705 706Selenium.prototype.doUncheck = function(locator) { 707 /** 708 * Uncheck a toggle-button (checkbox/radio) 709 * 710 * @param locator an <a href="#locators">element locator</a> 711 */ 712 this.findToggleButton(locator).checked = false; 713}; 714 715Selenium.prototype.doSelect = function(selectLocator, optionLocator) { 716 /** 717 * Select an option from a drop-down using an option locator. 718 * 719 * <p> 720 * Option locators provide different ways of specifying options of an HTML 721 * Select element (e.g. for selecting a specific option, or for asserting 722 * that the selected option satisfies a specification). There are several 723 * forms of Select Option Locator. 724 * </p> 725 * <ul> 726 * <li><strong>label</strong>=<em>labelPattern</em>: 727 * matches options based on their labels, i.e. the visible text. (This 728 * is the default.) 729 * <ul class="first last simple"> 730 * <li>label=regexp:^[Oo]ther</li> 731 * </ul> 732 * </li> 733 * <li><strong>value</strong>=<em>valuePattern</em>: 734 * matches options based on their values. 735 * <ul class="first last simple"> 736 * <li>value=other</li> 737 * </ul> 738 * 739 * 740 * </li> 741 * <li><strong>id</strong>=<em>id</em>: 742 * 743 * matches options based on their ids. 744 * <ul class="first last simple"> 745 * <li>id=option1</li> 746 * </ul> 747 * </li> 748 * <li><strong>index</strong>=<em>index</em>: 749 * matches an option based on its index (offset from zero). 750 * <ul class="first last simple"> 751 * 752 * <li>index=2</li> 753 * </ul> 754 * </li> 755 * </ul> 756 * <p> 757 * If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>. 758 * </p> 759 * 760 * 761 * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu 762 * @param optionLocator an option locator (a label by default) 763 */ 764 var element = this.browserbot.findElement(selectLocator); 765 if (!("options" in element)) { 766 throw new SeleniumError("Specified element is not a Select (has no options)"); 767 } 768 var locator = this.optionLocatorFactory.fromLocatorString(optionLocator); 769 var option = locator.findOption(element); 770 this.browserbot.selectOption(element, option); 771}; 772 773 774 775Selenium.prototype.doAddSelection = function(locator, optionLocator) { 776 /** 777 * Add a selection to the set of selected options in a multi-select element using an option locator. 778 * 779 * @see #doSelect for details of option locators 780 * 781 * @param locator an <a href="#locators">element locator</a> identifying a multi-select box 782 * @param optionLocator an option locator (a label by default) 783 */ 784 var element = this.browserbot.findElement(locator); 785 if (!("options" in element)) { 786 throw new SeleniumError("Specified element is not a Select (has no options)"); 787 } 788 var locator = this.optionLocatorFactory.fromLocatorString(optionLocator); 789 var option = locator.findOption(element); 790 this.browserbot.addSelection(element, option); 791}; 792 793Selenium.prototype.doRemoveSelection = function(locator, optionLocator) { 794 /** 795 * Remove a selection from the set of selected options in a multi-select element using an option locator. 796 * 797 * @see #doSelect for details of option locators 798 * 799 * @param locator an <a href="#locators">element locator</a> identifying a multi-select box 800 * @param optionLocator an option locator (a label by default) 801 */ 802 803 var element = this.browserbot.findElement(locator); 804 if (!("options" in element)) { 805 throw new SeleniumError("Specified element is not a Select (has no options)"); 806 } 807 var locator = this.optionLocatorFactory.fromLocatorString(optionLocator); 808 var option = locator.findOption(element); 809 this.browserbot.removeSelection(element, option); 810}; 811 812Selenium.prototype.doRemoveAllSelections = function(locator) { 813 /** 814 * Unselects all of the selected options in a multi-select element. 815 * 816 * @param locator an <a href="#locators">element locator</a> identifying a multi-select box 817 */ 818 var element = this.browserbot.findElement(locator); 819 if (!("options" in element)) { 820 throw new SeleniumError("Specified element is not a Select (has no options)"); 821 } 822 for (var i = 0; i < element.options.length; i++) { 823 this.browserbot.removeSelection(element, element.options[i]); 824 } 825} 826 827Selenium.prototype.doSubmit = function(formLocator) { 828 /** 829 * Submit the specified form. This is particularly useful for forms without 830 * submit buttons, e.g. single-input "Search" forms. 831 * 832 * @param formLocator an <a href="#locators">element locator</a> for the form you want to submit 833 */ 834 var form = this.browserbot.findElement(formLocator); 835 return this.browserbot.submit(form); 836 837}; 838 839Selenium.prototype.makePageLoadCondition = function(timeout) { 840 if (timeout == null) { 841 timeout = this.defaultTimeout; 842 } 843 // if the timeout is zero, we won't wait for the page to load before returning 844 if (timeout == 0) { 845 return; 846 } 847 return Selenium.decorateFunctionWithTimeout(fnBind(this._isNewPageLoaded, this), timeout); 848}; 849 850Selenium.prototype.doOpen = function(url) { 851 /** 852 * Opens an URL in the test frame. This accepts both relative and absolute 853 * URLs. 854 * 855 * The "open" command waits for the page to load before proceeding, 856 * ie. the "AndWait" suffix is implicit. 857 * 858 * <em>Note</em>: The URL must be on the same domain as the runner HTML 859 * due to security restrictions in the browser (Same Origin Policy). If you 860 * need to open an URL on another domain, use the Selenium Server to start a 861 * new browser session on that domain. 862 * 863 * @param url the URL to open; may be relative or absolute 864 */ 865 this.browserbot.openLocation(url); 866 if (window["proxyInjectionMode"] == null || !window["proxyInjectionMode"]) { 867 return this.makePageLoadCondition(); 868 } // in PI mode, just return "OK"; the server will waitForLoad 869}; 870 871Selenium.prototype.doOpenWindow = function(url, windowID) { 872 /** 873 * Opens a popup window (if a window with that ID isn't already open). 874 * After opening the window, you'll need to select it using the selectWindow 875 * command. 876 * 877 * <p>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). 878 * In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using 879 * an empty (blank) url, like this: openWindow("", "myFunnyWindow").</p> 880 * 881 * @param url the URL to open, which can be blank 882 * @param windowID the JavaScript window ID of the window to select 883 */ 884 this.browserbot.openWindow(url, windowID); 885}; 886 887Selenium.prototype.doSelectWindow = function(windowID) { 888 /** 889 * Selects a popup window using a window locator; once a popup window has been selected, all 890 * commands go to that window. To select the main window again, use null 891 * as the target. 892 * 893 * <p> 894 * 895 * Window locators provide different ways of specifying the window object: 896 * by title, by internal JavaScript "name," or by JavaScript variable. 897 * </p> 898 * <ul> 899 * <li><strong>title</strong>=<em>My Special Window</em>: 900 * Finds the window using the text that appears in the title bar. Be careful; 901 * two windows can share the same title. If that happens, this locator will 902 * just pick one. 903 * </li> 904 * <li><strong>name</strong>=<em>myWindow</em>: 905 * Finds the window using its internal JavaScript "name" property. This is the second 906 * parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) 907 * (which Selenium intercepts). 908 * </li> 909 * <li><strong>var</strong>=<em>variableName</em>: 910 * Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current 911 * application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using 912 * "var=foo". 913 * </li> 914 * </ul> 915 * <p> 916 * If no window locator prefix is provided, we'll try to guess what you mean like this:</p> 917 * <p>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).</p> 918 * <p>2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed 919 * that this variable contains the return value from a call to the JavaScript window.open() method.</p> 920 * <p>3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".</p> 921 * <p>4.) If <em>that</em> fails, we'll try looping over all of the known windows to try to find the appropriate "title". 922 * Since "title" is not necessarily unique, this may have unexpected behavior.</p> 923 * 924 * <p>If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messages 925 * which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages 926 * like the following for each window as it is opened:</p> 927 * 928 * <p><code>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</code></p> 929 * 930 * <p>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). 931 * (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 932 * an empty (blank) url, like this: openWindow("", "myFunnyWindow").</p> 933 * 934 * @param windowID the JavaScript window ID of the window to select 935 */ 936 this.browserbot.selectWindow(windowID); 937}; 938 939Selenium.prototype.doSelectFrame = function(locator) { 940 /** 941 * Selects a frame within the current window. (You may invoke this command 942 * multiple times to select nested frames.) To select the parent frame, use 943 * "relative=parent" as a locator; to select the top frame, use "relative=top". 944 * You can also select a frame by its 0-based index number; select the first frame with 945 * "index=0", or the third frame with "index=2". 946 * 947 * <p>You may also use a DOM expression to identify the frame you want directly, 948 * like this: <code>dom=frames["main"].frames["subframe"]</code></p> 949 * 950 * @param locator an <a href="#locators">element locator</a> identifying a frame or iframe 951 */ 952 this.browserbot.selectFrame(locator); 953}; 954 955Selenium.prototype.getWhetherThisFrameMatchFrameExpression = function(currentFrameString, target) { 956 /** 957 * Determine whether current/locator identify the frame containing this running code. 958 * 959 * <p>This is useful in proxy injection mode, where this code runs in every 960 * browser frame and window, and sometimes the selenium server needs to identify 961 * the "current" frame. In this case, when the test calls selectFrame, this 962 * routine is called for each frame to figure out which one has been selected. 963 * The selected frame will return true, while all others will return false.</p> 964 * 965 * @param currentFrameString starting frame 966 * @param target new frame (which might be relative to the current one) 967 * @return boolean true if the new frame is this code's window 968 */ 969 return this.browserbot.doesThisFrameMatchFrameExpression(currentFrameString, target); 970}; 971 972Selenium.prototype.getWhetherThisWindowMatchWindowExpression = function(currentWindowString, target) { 973 /** 974 * Determine whether currentWindowString plus target identify the window containing this running code. 975 * 976 * <p>This is useful in proxy injection mode, where this code runs in every 977 * browser frame and window, and sometimes the selenium server needs to identify 978 * the "current" window. In this case, when the test calls selectWindow, this 979 * routine is called for each window to figure out which one has been selected. 980 * The selected window will return true, while all others will return false.</p> 981 * 982 * @param currentWindowString starting window 983 * @param target new window (which might be relative to the current one, e.g., "_parent") 984 * @return boolean true if the new window is this code's window 985 */ 986 if (window.opener!=null && window.opener[target]!=null && window.opener[target]==window) { 987 return true; 988 } 989 return false; 990}; 991 992Selenium.prototype.doWaitForPopUp = function(windowID, timeout) { 993 /** 994 * Waits for a popup window to appear and load up. 995 * 996 * @param windowID the JavaScript window "name" of the window that will appear (not the text of the title bar) 997 * @param timeout a timeout in milliseconds, after which the action will return with an error 998 */ 999 var popupLoadedPredicate = function () { 1000 var targetWindow = selenium.browserbot.getWindowByName(windowID, true); 1001 if (!targetWindow) return false; 1002 if (!targetWindow.location) return false; 1003 if ("about:blank" == targetWindow.location) return false; 1004 if (browserVersion.isKonqueror) { 1005 if ("/" == targetWindow.location.href) { 1006 // apparently Konqueror uses this as the temporary location, instead of about:blank 1007 return false; 1008 } 1009 } 1010 if (browserVersion.isSafari) { 1011 if(targetWindow.location.href == selenium.browserbot.buttonWindow.location.href) { 1012 // Apparently Safari uses this as the temporary location, instead of about:blank 1013 // what a world! 1014 LOG.debug("DGF what a world!"); 1015 return false; 1016 } 1017 } 1018 if (!targetWindow.document) return false; 1019 if (!selenium.browserbot.getCurrentWindow().document.readyState) { 1020 // This is Firefox, with no readyState extension 1021 return true; 1022 } 1023 if ('complete' != targetWindow.document.readyState) return false; 1024 return true; 1025 }; 1026 1027 return Selenium.decorateFunctionWithTimeout(popupLoadedPredicate, timeout); 1028} 1029 1030Selenium.prototype.doWaitForPopUp.dontCheckAlertsAndConfirms = true; 1031 1032Selenium.prototype.doChooseCancelOnNextConfirmation = function() { 1033 /** 1034 * <p> 1035 * By default, Selenium's overridden window.confirm() function will 1036 * return true, as if the user had manually clicked OK; after running 1037 * this command, the next call to confirm() will return false, as if 1038 * the user had clicked Cancel. Selenium will then resume using the 1039 * default behavior for future confirmations, automatically returning 1040 * true (OK) unless/until you explicitly call this command for each 1041 * confirmation. 1042 * </p> 1043 * <p> 1044 * Take note - every time a confirmation comes up, you must 1045 * consume it with a corresponding getConfirmation, or else 1046 * the next selenium operation will fail. 1047 * </p> 1048 */ 1049 this.browserbot.cancelNextConfirmation(false); 1050}; 1051 1052Selenium.prototype.doChooseOkOnNextConfirmation = function() { 1053 /** 1054 * <p> 1055 * Undo the effect of calling chooseCancelOnNextConfirmation. Note 1056 * that Selenium's overridden window.confirm() function will normally automatically 1057 * return true, as if the user had manually clicked OK, so you shouldn't 1058 * need to use this command unless for some reason you need to change 1059 * your mind prior to the next confirmation. After any confirmation, Selenium will resume using the 1060 * default behavior for future confirmations, automatically returning 1061 * true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each 1062 * confirmation. 1063 * </p> 1064 * <p> 1065 * Take note - every time a confirmation comes up, you must 1066 * consume it with a corresponding getConfirmation, or else 1067 * the next selenium operation will fail. 1068 * </p> 1069 * 1070 */ 1071 this.browserbot.cancelNextConfirmation(true); 1072}; 1073 1074Selenium.prototype.doAnswerOnNextPrompt = function(answer) { 1075 /** 1076 * Instructs Selenium to return the specified answer string in response to 1077 * the next JavaScript prompt [window.prompt()]. 1078 * 1079 * 1080 * @param answer the answer to give in response to the prompt pop-up 1081 */ 1082 this.browserbot.setNextPromptResult(answer); 1083}; 1084 1085Selenium.prototype.doGoBack = function() { 1086 /** 1087 * Simulates the user clicking the "back" button on their browser. 1088 * 1089 */ 1090 this.browserbot.goBack(); 1091}; 1092 1093Selenium.prototype.doRefresh = function() { 1094 /** 1095 * Simulates the user clicking the "Refresh" button on their browser. 1096 * 1097 */ 1098 this.browserbot.refresh(); 1099}; 1100 1101Selenium.prototype.doClose = function() { 1102 /** 1103 * Simulates the user clicking the "close" button in the titlebar of a popup 1104 * window or tab. 1105 */ 1106 this.browserbot.close(); 1107}; 1108 1109Selenium.prototype.ensureNoUnhandledPopups = function() { 1110 if (this.browserbot.hasAlerts()) { 1111 throw new SeleniumError("There was an unexpected Alert! [" + this.browserbot.getNextAlert() + "]"); 1112 } 1113 if ( this.browserbot.hasConfirmations() ) { 1114 throw new SeleniumError("There was an unexpected Confirmation! [" + this.browserbot.getNextConfirmation() + "]"); 1115 } 1116}; 1117 1118Selenium.prototype.isAlertPresent = function() { 1119 /** 1120 * Has an alert occurred? 1121 * 1122 * <p> 1123 * This function never throws an exception 1124 * </p> 1125 * @return boolean true if there is an alert 1126 */ 1127 return this.browserbot.hasAlerts(); 1128}; 1129 1130Selenium.prototype.isPromptPresent = function() { 1131 /** 1132 * Has a prompt occurred? 1133 * 1134 * <p> 1135 * This function never throws an exception 1136 * </p> 1137 * @return boolean true if there is a pending prompt 1138 */ 1139 return this.browserbot.hasPrompts(); 1140}; 1141 1142Selenium.prototype.isConfirmationPresent = function() { 1143 /** 1144 * Has confirm() been called? 1145 * 1146 * <p> 1147 * This function never throws an exception 1148 * </p> 1149 * @return boolean true if there is a pending confirmation 1150 */ 1151 return this.browserbot.hasConfirmations(); 1152}; 1153Selenium.prototype.getAlert = function() { 1154 /** 1155 * Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts. 1156 * 1157 * <p>Getting an alert has the same effect as manually clicking OK. If an 1158 * alert is generated but you do not consume it with getAlert, the next Selenium action 1159 * will fail.</p> 1160 * 1161 * <p>Under Selenium, JavaScript alerts will NOT pop up a visible alert 1162 * dialog.</p> 1163 * 1164 * <p>Selenium does NOT support JavaScript alerts that are generated in a 1165 * page's onload() event handler. In this case a visible dialog WILL be 1166 * generated and Selenium will hang until someone manually clicks OK.</p> 1167 * @return string The message of the most recent JavaScript alert 1168 1169 */ 1170 if (!this.browserbot.hasAlerts()) { 1171 Assert.fail("There were no alerts"); 1172 } 1173 return this.browserbot.getNextAlert(); 1174}; 1175Selenium.prototype.getAlert.dontCheckAlertsAndConfirms = true; 1176 1177Selenium.prototype.getConfirmation = function() { 1178 /** 1179 * Retrieves the message of a JavaScript confirmation dialog generated during 1180 * the previous action. 1181 * 1182 * <p> 1183 * By default, the confirm function will return true, having the same effect 1184 * as manually clicking OK. This can be changed by prior execution of the 1185 * chooseCancelOnNextConfirmation command. 1186 * </p> 1187 * <p> 1188 * If an confirmation is generated but you do not consume it with getConfirmation, 1189 * the next Selenium action will fail. 1190 * </p> 1191 * 1192 * <p> 1193 * NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible 1194 * dialog. 1195 * </p> 1196 * 1197 * <p> 1198 * NOTE: Selenium does NOT support JavaScript confirmations that are 1199 * generated in a page's onload() event handler. In this case a visible 1200 * dialog WILL be generated and Selenium will hang until you manually click 1201 * OK. 1202 * </p> 1203 * 1204 * @return string the message of the most recent JavaScript confirmation dialog 1205 */ 1206 if (!this.browserbot.hasConfirmations()) { 1207 Assert.fail("There were no confirmations"); 1208 } 1209 return this.browserbot.getNextConfirmation(); 1210}; 1211Selenium.prototype.getConfirmation.dontCheckAlertsAndConfirms = true; 1212 1213Selenium.prototype.getPrompt = function() { 1214 /** 1215 * Retrieves the message of a JavaScript question prompt dialog generated during 1216 * the previous action. 1217 * 1218 * <p>Successful handling of the prompt requires prior execution of the 1219 * answerOnNextPrompt command. If a prompt is generated but you 1220 * do not get/verify it, the next Selenium action will fail.</p> 1221 * 1222 * <p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible 1223 * dialog.</p> 1224 * 1225 * <p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a 1226 * page's onload() event handler. In this case a visible dialog WILL be 1227 * generated and Selenium will hang until someone manually clicks OK.</p> 1228 * @return string the message of the most recent JavaScript question prompt 1229 */ 1230 if (! this.browserbot.hasPrompts()) { 1231 Assert.fail("There were no prompts"); 1232 } 1233 return this.browserbot.getNextPrompt(); 1234}; 1235 1236Selenium.prototype.getLocation = function() { 1237 /** Gets the absolute URL of the current page. 1238 * 1239 * @return string the absolute URL of the current page 1240 */ 1241 return this.browserbot.getCurrentWindow().location.href; 1242}; 1243 1244Selenium.prototype.getTitle = function() { 1245 /** Gets the title of the current page. 1246 * 1247 * @return string the title of the current page 1248 */ 1249 return this.browserbot.getTitle(); 1250}; 1251 1252 1253Selenium.prototype.getBodyText = function() { 1254 /** 1255 * Gets the entire text of the page. 1256 * @return string the entire text of the page 1257 */ 1258 return this.browserbot.bodyText(); 1259}; 1260 1261 1262Selenium.prototype.getValue = function(locator) { 1263 /** 1264 * Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). 1265 * For checkbox/radio elements, the value will be "on" or "off" depending on 1266 * whether the element is checked or not. 1267 * 1268 * @param locator an <a href="#locators">element locator</a> 1269 * @return string the element value, or "on/off" for checkbox/radio elements 1270 */ 1271 var element = this.browserbot.findElement(locator) 1272 return getInputValue(element).trim(); 1273} 1274 1275Selenium.prototype.getText = function(locator) { 1276 /** 1277 * Gets the text of an element. This works for any element that contains 1278 * text. This command uses either the textContent (Mozilla-like browsers) or 1279 * the innerText (IE-like browsers) of the element, which is the rendered 1280 * text shown to the user. 1281 * 1282 * @param locator an <a href="#locators">element locator</a> 1283 * @return string the text of the element 1284 */ 1285 var element = this.browserbot.findElement(locator); 1286 return getText(element).trim(); 1287}; 1288 1289Selenium.prototype.doHighlight = function(locator) { 1290 /** 1291 * Briefly changes the backgroundColor of the specified element yellow. Useful for debugging. 1292 * 1293 * @param locator an <a href="#locators">element locator</a> 1294 …
Large files files are truncated, but you can click here to view the full file