PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/php/src/Selenium.php

http://flash-selenium.googlecode.com/
PHP | 2133 lines | 488 code | 241 blank | 1404 comment | 0 complexity | 938b8f0fd29f69cbafc8b4d293e9a042 MD5 | raw file
  1. <?php
  2. /** Copyright 2006 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. * This file has been automatically generated via XSL
  18. * -----------------
  19. *
  20. *
  21. *
  22. * @category Testing
  23. * @package Selenium
  24. * @author Shin Ohno <ganchiku at gmail dot com>
  25. * @author Bjoern Schotte <schotte at mayflower dot de>
  26. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  27. * @version 0.4.2
  28. * @see http://www.openqa.org/selenium-rc/
  29. * @since 0.1
  30. */
  31. /**
  32. * Selenium exception class
  33. */
  34. require_once 'Testing/Selenium/Exception.php';
  35. /**
  36. * Defines an object that runs Selenium commands.
  37. *
  38. *
  39. * <p>
  40. * <b>Element Locators</b>
  41. * </p><p>
  42. *
  43. * Element Locators tell Selenium which HTML element a command refers to.
  44. * The format of a locator is:
  45. * </p><p>
  46. *
  47. * <i>locatorType</i><b>=</b><i>argument</i>
  48. * </p>
  49. * <p>
  50. *
  51. * We support the following strategies for locating elements:
  52. *
  53. * </p>
  54. * <ul>
  55. *
  56. * <li>
  57. * <b>identifier</b>=<i>id</i>:
  58. * Select the element with the specified @id attribute. If no match is
  59. * found, select the first element whose @name attribute is <i>id</i>.
  60. * (This is normally the default; see below.)
  61. * </li>
  62. * <li>
  63. * <b>id</b>=<i>id</i>:
  64. * Select the element with the specified @id attribute.
  65. * </li>
  66. * <li>
  67. * <b>name</b>=<i>name</i>:
  68. * Select the first element with the specified @name attribute.
  69. *
  70. * <ul>
  71. *
  72. * <li>
  73. * username
  74. * </li>
  75. * <li>
  76. * name=username
  77. * </li>
  78. * </ul>
  79. <p>
  80. * The name may optionally be followed by one or more <i>element-filters</i>, separated from the name by whitespace. If the <i>filterType</i> is not specified, <b>value</b> is assumed.
  81. * </p>
  82. * <ul>
  83. *
  84. * <li>
  85. * name=flavour value=chocolate
  86. * </li>
  87. * </ul>
  88. * </li>
  89. * <li>
  90. * <b>dom</b>=<i>javascriptExpression</i>:
  91. *
  92. * Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
  93. * Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
  94. *
  95. * <ul>
  96. *
  97. * <li>
  98. * dom=document.forms['myForm'].myDropdown
  99. * </li>
  100. * <li>
  101. * dom=document.images[56]
  102. * </li>
  103. * <li>
  104. * dom=function foo() { return document.links[1]; }; foo();
  105. * </li>
  106. * </ul>
  107. * </li>
  108. * <li>
  109. * <b>xpath</b>=<i>xpathExpression</i>:
  110. * Locate an element using an XPath expression.
  111. *
  112. * <ul>
  113. *
  114. * <li>
  115. * xpath=//img[@alt='The image alt text']
  116. * </li>
  117. * <li>
  118. * xpath=//table[@id='table1']//tr[4]/td[2]
  119. * </li>
  120. * <li>
  121. * xpath=//a[contains(@href,'#id1')]
  122. * </li>
  123. * <li>
  124. * xpath=//a[contains(@href,'#id1')]/@class
  125. * </li>
  126. * <li>
  127. * xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
  128. * </li>
  129. * <li>
  130. * xpath=//input[@name='name2' and @value='yes']
  131. * </li>
  132. * <li>
  133. * xpath=//*[text()="right"]
  134. * </li>
  135. * </ul>
  136. * </li>
  137. * <li>
  138. * <b>link</b>=<i>textPattern</i>:
  139. * Select the link (anchor) element which contains text matching the
  140. * specified <i>pattern</i>.
  141. *
  142. * <ul>
  143. *
  144. * <li>
  145. * link=The link text
  146. * </li>
  147. * </ul>
  148. * </li>
  149. * <li>
  150. * <b>css</b>=<i>cssSelectorSyntax</i>:
  151. * 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.
  152. *
  153. * <ul>
  154. *
  155. * <li>
  156. * css=a[href="#id3"]
  157. * </li>
  158. * <li>
  159. * css=span#firstChild + span
  160. * </li>
  161. * </ul>
  162. <p>
  163. * 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).
  164. * </p>
  165. * </li>
  166. * </ul><p>
  167. *
  168. * Without an explicit locator prefix, Selenium uses the following default
  169. * strategies:
  170. *
  171. * </p>
  172. * <ul>
  173. *
  174. * <li>
  175. * <b>dom</b>, for locators starting with "document."
  176. * </li>
  177. * <li>
  178. * <b>xpath</b>, for locators starting with "//"
  179. * </li>
  180. * <li>
  181. * <b>identifier</b>, otherwise
  182. * </li>
  183. * </ul>
  184. * <p>
  185. * <b>Element Filters</b>
  186. * </p><p>
  187. *
  188. * <p>
  189. * 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.
  190. * </p>
  191. <p>
  192. * Filters look much like locators, ie.
  193. * </p>
  194. <p>
  195. *
  196. * <i>filterType</i><b>=</b><i>argument</i>
  197. * </p>
  198. * <p>
  199. * Supported element-filters are:
  200. * </p>
  201. <p>
  202. * <b>value=</b><i>valuePattern</i>
  203. * </p>
  204. <p>
  205. *
  206. *
  207. * Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.
  208. * </p>
  209. * <p>
  210. * <b>index=</b><i>index</i>
  211. * </p>
  212. <p>
  213. *
  214. *
  215. * Selects a single element based on its position in the list (offset from zero).
  216. * </p>
  217. *
  218. * </p>
  219. *
  220. * <p>
  221. * <b>String-match Patterns</b>
  222. * </p><p>
  223. *
  224. * Various Pattern syntaxes are available for matching string values:
  225. *
  226. * </p>
  227. * <ul>
  228. *
  229. * <li>
  230. * <b>glob:</b><i>pattern</i>:
  231. * Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
  232. * kind of limited regular-expression syntax typically used in command-line
  233. * shells. In a glob pattern, "*" represents any sequence of characters, and "?"
  234. * represents any single character. Glob patterns match against the entire
  235. * string.
  236. * </li>
  237. * <li>
  238. * <b>regexp:</b><i>regexp</i>:
  239. * Match a string using a regular-expression. The full power of JavaScript
  240. * regular-expressions is available.
  241. * </li>
  242. * <li>
  243. * <b>regexpi:</b><i>regexpi</i>:
  244. * Match a string using a case-insensitive regular-expression.
  245. * </li>
  246. * <li>
  247. * <b>exact:</b><i>string</i>:
  248. *
  249. * Match a string exactly, verbatim, without any of that fancy wildcard
  250. * stuff.
  251. * </li>
  252. * </ul><p>
  253. *
  254. * If no pattern prefix is specified, Selenium assumes that it's a "glob"
  255. * pattern.
  256. *
  257. * </p>
  258. *
  259. * @package Selenium
  260. * @author Shin Ohno <ganchiku at gmail dot com>
  261. * @author Bjoern Schotte <schotte at mayflower dot de>
  262. */
  263. class Testing_Selenium
  264. {
  265. /**
  266. * @var string
  267. * @access private
  268. */
  269. private $browser;
  270. /**
  271. * @var string
  272. * @access private
  273. */
  274. private $browserUrl;
  275. /**
  276. * @var string
  277. * @access private
  278. */
  279. private $host;
  280. /**
  281. * @var int
  282. * @access private
  283. */
  284. private $port;
  285. /**
  286. * @var string
  287. * @access private
  288. */
  289. private $sessionId;
  290. /**
  291. * @var string
  292. * @access private
  293. */
  294. private $timeout;
  295. /**
  296. * Constructor
  297. *
  298. * @param string $browser
  299. * @param string $browserUrl
  300. * @param string $host
  301. * @param int $port
  302. * @param int $timeout
  303. * @access public
  304. * @throws Testing_Selenium_Exception
  305. */
  306. public function __construct($browser, $browserUrl, $host = 'localhost', $port = 4444, $timeout = 30000)
  307. {
  308. $this->browser = $browser;
  309. $this->browserUrl = $browserUrl;
  310. $this->host = $host;
  311. $this->port = $port;
  312. $this->timeout = $timeout;
  313. }
  314. /**
  315. * Run the browser and set session id.
  316. *
  317. * @access public
  318. * @return void
  319. */
  320. public function start()
  321. {
  322. $this->sessionId = $this->getString("getNewBrowserSession", array($this->browser, $this->browserUrl));
  323. return $this->sessionId;
  324. }
  325. /**
  326. * Close the browser and set session id null
  327. *
  328. * @access public
  329. * @return void
  330. */
  331. public function stop()
  332. {
  333. $this->doCommand("testComplete");
  334. $this->sessionId = null;
  335. }
  336. /**
  337. * Clicks on a link, button, checkbox or radio button. If the click action
  338. * causes a new page to load (like a link usually does), call
  339. * waitForPageToLoad.
  340. *
  341. * @access public
  342. * @param string $locator an element locator
  343. */
  344. public function click($locator)
  345. {
  346. $this->doCommand("click", array($locator));
  347. }
  348. /**
  349. * Double clicks on a link, button, checkbox or radio button. If the double click action
  350. * causes a new page to load (like a link usually does), call
  351. * waitForPageToLoad.
  352. *
  353. * @access public
  354. * @param string $locator an element locator
  355. */
  356. public function doubleClick($locator)
  357. {
  358. $this->doCommand("doubleClick", array($locator));
  359. }
  360. /**
  361. * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
  362. *
  363. * @access public
  364. * @param string $locator an element locator
  365. */
  366. public function contextMenu($locator)
  367. {
  368. $this->doCommand("contextMenu", array($locator));
  369. }
  370. /**
  371. * Clicks on a link, button, checkbox or radio button. If the click action
  372. * causes a new page to load (like a link usually does), call
  373. * waitForPageToLoad.
  374. *
  375. * @access public
  376. * @param string $locator an element locator
  377. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  378. */
  379. public function clickAt($locator, $coordString)
  380. {
  381. $this->doCommand("clickAt", array($locator, $coordString));
  382. }
  383. /**
  384. * Doubleclicks on a link, button, checkbox or radio button. If the action
  385. * causes a new page to load (like a link usually does), call
  386. * waitForPageToLoad.
  387. *
  388. * @access public
  389. * @param string $locator an element locator
  390. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  391. */
  392. public function doubleClickAt($locator, $coordString)
  393. {
  394. $this->doCommand("doubleClickAt", array($locator, $coordString));
  395. }
  396. /**
  397. * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
  398. *
  399. * @access public
  400. * @param string $locator an element locator
  401. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  402. */
  403. public function contextMenuAt($locator, $coordString)
  404. {
  405. $this->doCommand("contextMenuAt", array($locator, $coordString));
  406. }
  407. /**
  408. * Explicitly simulate an event, to trigger the corresponding "on<i>event</i>"
  409. * handler.
  410. *
  411. * @access public
  412. * @param string $locator an element locator
  413. * @param string $eventName the event name, e.g. "focus" or "blur"
  414. */
  415. public function fireEvent($locator, $eventName)
  416. {
  417. $this->doCommand("fireEvent", array($locator, $eventName));
  418. }
  419. /**
  420. * Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
  421. *
  422. * @access public
  423. * @param string $locator an element locator
  424. */
  425. public function focus($locator)
  426. {
  427. $this->doCommand("focus", array($locator));
  428. }
  429. /**
  430. * Simulates a user pressing and releasing a key.
  431. *
  432. * @access public
  433. * @param string $locator an element locator
  434. * @param string $keySequence 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".
  435. */
  436. public function keyPress($locator, $keySequence)
  437. {
  438. $this->doCommand("keyPress", array($locator, $keySequence));
  439. }
  440. /**
  441. * Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
  442. *
  443. * @access public
  444. */
  445. public function shiftKeyDown()
  446. {
  447. $this->doCommand("shiftKeyDown", array());
  448. }
  449. /**
  450. * Release the shift key.
  451. *
  452. * @access public
  453. */
  454. public function shiftKeyUp()
  455. {
  456. $this->doCommand("shiftKeyUp", array());
  457. }
  458. /**
  459. * Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
  460. *
  461. * @access public
  462. */
  463. public function metaKeyDown()
  464. {
  465. $this->doCommand("metaKeyDown", array());
  466. }
  467. /**
  468. * Release the meta key.
  469. *
  470. * @access public
  471. */
  472. public function metaKeyUp()
  473. {
  474. $this->doCommand("metaKeyUp", array());
  475. }
  476. /**
  477. * Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
  478. *
  479. * @access public
  480. */
  481. public function altKeyDown()
  482. {
  483. $this->doCommand("altKeyDown", array());
  484. }
  485. /**
  486. * Release the alt key.
  487. *
  488. * @access public
  489. */
  490. public function altKeyUp()
  491. {
  492. $this->doCommand("altKeyUp", array());
  493. }
  494. /**
  495. * Press the control key and hold it down until doControlUp() is called or a new page is loaded.
  496. *
  497. * @access public
  498. */
  499. public function controlKeyDown()
  500. {
  501. $this->doCommand("controlKeyDown", array());
  502. }
  503. /**
  504. * Release the control key.
  505. *
  506. * @access public
  507. */
  508. public function controlKeyUp()
  509. {
  510. $this->doCommand("controlKeyUp", array());
  511. }
  512. /**
  513. * Simulates a user pressing a key (without releasing it yet).
  514. *
  515. * @access public
  516. * @param string $locator an element locator
  517. * @param string $keySequence 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".
  518. */
  519. public function keyDown($locator, $keySequence)
  520. {
  521. $this->doCommand("keyDown", array($locator, $keySequence));
  522. }
  523. /**
  524. * Simulates a user releasing a key.
  525. *
  526. * @access public
  527. * @param string $locator an element locator
  528. * @param string $keySequence 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".
  529. */
  530. public function keyUp($locator, $keySequence)
  531. {
  532. $this->doCommand("keyUp", array($locator, $keySequence));
  533. }
  534. /**
  535. * Simulates a user hovering a mouse over the specified element.
  536. *
  537. * @access public
  538. * @param string $locator an element locator
  539. */
  540. public function mouseOver($locator)
  541. {
  542. $this->doCommand("mouseOver", array($locator));
  543. }
  544. /**
  545. * Simulates a user moving the mouse pointer away from the specified element.
  546. *
  547. * @access public
  548. * @param string $locator an element locator
  549. */
  550. public function mouseOut($locator)
  551. {
  552. $this->doCommand("mouseOut", array($locator));
  553. }
  554. /**
  555. * Simulates a user pressing the mouse button (without releasing it yet) on
  556. * the specified element.
  557. *
  558. * @access public
  559. * @param string $locator an element locator
  560. */
  561. public function mouseDown($locator)
  562. {
  563. $this->doCommand("mouseDown", array($locator));
  564. }
  565. /**
  566. * Simulates a user pressing the mouse button (without releasing it yet) at
  567. * the specified location.
  568. *
  569. * @access public
  570. * @param string $locator an element locator
  571. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  572. */
  573. public function mouseDownAt($locator, $coordString)
  574. {
  575. $this->doCommand("mouseDownAt", array($locator, $coordString));
  576. }
  577. /**
  578. * Simulates the event that occurs when the user releases the mouse button (i.e., stops
  579. * holding the button down) on the specified element.
  580. *
  581. * @access public
  582. * @param string $locator an element locator
  583. */
  584. public function mouseUp($locator)
  585. {
  586. $this->doCommand("mouseUp", array($locator));
  587. }
  588. /**
  589. * Simulates the event that occurs when the user releases the mouse button (i.e., stops
  590. * holding the button down) at the specified location.
  591. *
  592. * @access public
  593. * @param string $locator an element locator
  594. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  595. */
  596. public function mouseUpAt($locator, $coordString)
  597. {
  598. $this->doCommand("mouseUpAt", array($locator, $coordString));
  599. }
  600. /**
  601. * Simulates a user pressing the mouse button (without releasing it yet) on
  602. * the specified element.
  603. *
  604. * @access public
  605. * @param string $locator an element locator
  606. */
  607. public function mouseMove($locator)
  608. {
  609. $this->doCommand("mouseMove", array($locator));
  610. }
  611. /**
  612. * Simulates a user pressing the mouse button (without releasing it yet) on
  613. * the specified element.
  614. *
  615. * @access public
  616. * @param string $locator an element locator
  617. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  618. */
  619. public function mouseMoveAt($locator, $coordString)
  620. {
  621. $this->doCommand("mouseMoveAt", array($locator, $coordString));
  622. }
  623. /**
  624. * Sets the value of an input field, as though you typed it in.
  625. *
  626. * <p>
  627. * Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
  628. * value should be the value of the option selected, not the visible text.
  629. * </p>
  630. *
  631. * @access public
  632. * @param string $locator an element locator
  633. * @param string $value the value to type
  634. */
  635. public function type($locator, $value)
  636. {
  637. $this->doCommand("type", array($locator, $value));
  638. }
  639. /**
  640. * Simulates keystroke events on the specified element, as though you typed the value key-by-key.
  641. *
  642. * <p>
  643. * This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;
  644. * this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
  645. * </p><p>
  646. * Unlike the simple "type" command, which forces the specified value into the page directly, this command
  647. * may or may not have any visible effect, even in cases where typing keys would normally have a visible effect.
  648. * For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in
  649. * the field.
  650. * </p><p>
  651. * 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
  652. * send the keystroke events corresponding to what you just typed.
  653. * </p>
  654. *
  655. * @access public
  656. * @param string $locator an element locator
  657. * @param string $value the value to type
  658. */
  659. public function typeKeys($locator, $value)
  660. {
  661. $this->doCommand("typeKeys", array($locator, $value));
  662. }
  663. /**
  664. * 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.,
  665. * the delay is 0 milliseconds.
  666. *
  667. * @access public
  668. * @param string $value the number of milliseconds to pause after operation
  669. */
  670. public function setSpeed($value)
  671. {
  672. $this->doCommand("setSpeed", array($value));
  673. }
  674. /**
  675. * 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.,
  676. * the delay is 0 milliseconds.
  677. *
  678. * See also setSpeed.
  679. *
  680. * @access public
  681. */
  682. public function getSpeed()
  683. {
  684. $this->doCommand("getSpeed", array());
  685. }
  686. /**
  687. * Check a toggle-button (checkbox/radio)
  688. *
  689. * @access public
  690. * @param string $locator an element locator
  691. */
  692. public function check($locator)
  693. {
  694. $this->doCommand("check", array($locator));
  695. }
  696. /**
  697. * Uncheck a toggle-button (checkbox/radio)
  698. *
  699. * @access public
  700. * @param string $locator an element locator
  701. */
  702. public function uncheck($locator)
  703. {
  704. $this->doCommand("uncheck", array($locator));
  705. }
  706. /**
  707. * Select an option from a drop-down using an option locator.
  708. *
  709. * <p>
  710. *
  711. * Option locators provide different ways of specifying options of an HTML
  712. * Select element (e.g. for selecting a specific option, or for asserting
  713. * that the selected option satisfies a specification). There are several
  714. * forms of Select Option Locator.
  715. *
  716. * </p>
  717. * <ul>
  718. *
  719. * <li>
  720. * <b>label</b>=<i>labelPattern</i>:
  721. * matches options based on their labels, i.e. the visible text. (This
  722. * is the default.)
  723. *
  724. * <ul>
  725. *
  726. * <li>
  727. * label=regexp:^[Oo]ther
  728. * </li>
  729. * </ul>
  730. * </li>
  731. * <li>
  732. * <b>value</b>=<i>valuePattern</i>:
  733. * matches options based on their values.
  734. *
  735. * <ul>
  736. *
  737. * <li>
  738. * value=other
  739. * </li>
  740. * </ul>
  741. * </li>
  742. * <li>
  743. * <b>id</b>=<i>id</i>:
  744. *
  745. * matches options based on their ids.
  746. *
  747. * <ul>
  748. *
  749. * <li>
  750. * id=option1
  751. * </li>
  752. * </ul>
  753. * </li>
  754. * <li>
  755. * <b>index</b>=<i>index</i>:
  756. * matches an option based on its index (offset from zero).
  757. *
  758. * <ul>
  759. *
  760. * <li>
  761. * index=2
  762. * </li>
  763. * </ul>
  764. * </li>
  765. * </ul><p>
  766. *
  767. * If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
  768. *
  769. * </p>
  770. *
  771. * @access public
  772. * @param string $selectLocator an element locator identifying a drop-down menu
  773. * @param string $optionLocator an option locator (a label by default)
  774. */
  775. public function select($selectLocator, $optionLocator)
  776. {
  777. $this->doCommand("select", array($selectLocator, $optionLocator));
  778. }
  779. /**
  780. * Add a selection to the set of selected options in a multi-select element using an option locator.
  781. *
  782. * @see #doSelect for details of option locators
  783. *
  784. * @access public
  785. * @param string $locator an element locator identifying a multi-select box
  786. * @param string $optionLocator an option locator (a label by default)
  787. */
  788. public function addSelection($locator, $optionLocator)
  789. {
  790. $this->doCommand("addSelection", array($locator, $optionLocator));
  791. }
  792. /**
  793. * Remove a selection from the set of selected options in a multi-select element using an option locator.
  794. *
  795. * @see #doSelect for details of option locators
  796. *
  797. * @access public
  798. * @param string $locator an element locator identifying a multi-select box
  799. * @param string $optionLocator an option locator (a label by default)
  800. */
  801. public function removeSelection($locator, $optionLocator)
  802. {
  803. $this->doCommand("removeSelection", array($locator, $optionLocator));
  804. }
  805. /**
  806. * Unselects all of the selected options in a multi-select element.
  807. *
  808. * @access public
  809. * @param string $locator an element locator identifying a multi-select box
  810. */
  811. public function removeAllSelections($locator)
  812. {
  813. $this->doCommand("removeAllSelections", array($locator));
  814. }
  815. /**
  816. * Submit the specified form. This is particularly useful for forms without
  817. * submit buttons, e.g. single-input "Search" forms.
  818. *
  819. * @access public
  820. * @param string $formLocator an element locator for the form you want to submit
  821. */
  822. public function submit($formLocator)
  823. {
  824. $this->doCommand("submit", array($formLocator));
  825. }
  826. /**
  827. * Opens an URL in the test frame. This accepts both relative and absolute
  828. * URLs.
  829. *
  830. * The "open" command waits for the page to load before proceeding,
  831. * ie. the "AndWait" suffix is implicit.
  832. *
  833. * <i>Note</i>: The URL must be on the same domain as the runner HTML
  834. * due to security restrictions in the browser (Same Origin Policy). If you
  835. * need to open an URL on another domain, use the Selenium Server to start a
  836. * new browser session on that domain.
  837. *
  838. * @access public
  839. * @param string $url the URL to open; may be relative or absolute
  840. */
  841. public function open($url)
  842. {
  843. $this->doCommand("open", array($url));
  844. }
  845. /**
  846. * Opens a popup window (if a window with that ID isn't already open).
  847. * After opening the window, you'll need to select it using the selectWindow
  848. * command.
  849. *
  850. * <p>
  851. * 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).
  852. * In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
  853. * an empty (blank) url, like this: openWindow("", "myFunnyWindow").
  854. * </p>
  855. *
  856. * @access public
  857. * @param string $url the URL to open, which can be blank
  858. * @param string $windowID the JavaScript window ID of the window to select
  859. */
  860. public function openWindow($url, $windowID)
  861. {
  862. $this->doCommand("openWindow", array($url, $windowID));
  863. }
  864. /**
  865. * Selects a popup window; once a popup window has been selected, all
  866. * commands go to that window. To select the main window again, use null
  867. * as the target.
  868. *
  869. * <p>
  870. * Note that there is a big difference between a window's internal JavaScript "name" property
  871. * and the "title" of a given window's document (which is normally what you actually see, as an end user,
  872. * in the title bar of the window). The "name" is normally invisible to the end-user; it's the second
  873. * parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
  874. * (which selenium intercepts).
  875. * </p><p>
  876. * Selenium has several strategies for finding the window object referred to by the "windowID" parameter.
  877. * </p><p>
  878. * 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).
  879. * </p><p>
  880. * 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
  881. * that this variable contains the return value from a call to the JavaScript window.open() method.
  882. * </p><p>
  883. * 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".
  884. * </p><p>
  885. * 4.) If <i>that</i> fails, we'll try looping over all of the known windows to try to find the appropriate "title".
  886. * Since "title" is not necessarily unique, this may have unexpected behavior.
  887. * </p><p>
  888. * If you're having trouble figuring out what is the name of a window that you want to manipulate, look at the selenium log messages
  889. * which identify the names of windows created via window.open (and therefore intercepted by selenium). You will see messages
  890. * like the following for each window as it is opened:
  891. * </p><p>
  892. * <code>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</code>
  893. * </p><p>
  894. * 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).
  895. * (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
  896. * an empty (blank) url, like this: openWindow("", "myFunnyWindow").
  897. * </p>
  898. *
  899. * @access public
  900. * @param string $windowID the JavaScript window ID of the window to select
  901. */
  902. public function selectWindow($windowID)
  903. {
  904. $this->doCommand("selectWindow", array($windowID));
  905. }
  906. /**
  907. * Selects a frame within the current window. (You may invoke this command
  908. * multiple times to select nested frames.) To select the parent frame, use
  909. * "relative=parent" as a locator; to select the top frame, use "relative=top".
  910. * You can also select a frame by its 0-based index number; select the first frame with
  911. * "index=0", or the third frame with "index=2".
  912. *
  913. * <p>
  914. * You may also use a DOM expression to identify the frame you want directly,
  915. * like this: <code>dom=frames["main"].frames["subframe"]</code>
  916. * </p>
  917. *
  918. * @access public
  919. * @param string $locator an element locator identifying a frame or iframe
  920. */
  921. public function selectFrame($locator)
  922. {
  923. $this->doCommand("selectFrame", array($locator));
  924. }
  925. /**
  926. * Determine whether current/locator identify the frame containing this running code.
  927. *
  928. * <p>
  929. * This is useful in proxy injection mode, where this code runs in every
  930. * browser frame and window, and sometimes the selenium server needs to identify
  931. * the "current" frame. In this case, when the test calls selectFrame, this
  932. * routine is called for each frame to figure out which one has been selected.
  933. * The selected frame will return true, while all others will return false.
  934. * </p>
  935. *
  936. * @access public
  937. * @param string $currentFrameString starting frame
  938. * @param string $target new frame (which might be relative to the current one)
  939. * @return boolean true if the new frame is this code's window
  940. */
  941. public function getWhetherThisFrameMatchFrameExpression($currentFrameString, $target)
  942. {
  943. return $this->getBoolean("getWhetherThisFrameMatchFrameExpression", array($currentFrameString, $target));
  944. }
  945. /**
  946. * Determine whether currentWindowString plus target identify the window containing this running code.
  947. *
  948. * <p>
  949. * This is useful in proxy injection mode, where this code runs in every
  950. * browser frame and window, and sometimes the selenium server needs to identify
  951. * the "current" window. In this case, when the test calls selectWindow, this
  952. * routine is called for each window to figure out which one has been selected.
  953. * The selected window will return true, while all others will return false.
  954. * </p>
  955. *
  956. * @access public
  957. * @param string $currentWindowString starting window
  958. * @param string $target new window (which might be relative to the current one, e.g., "_parent")
  959. * @return boolean true if the new window is this code's window
  960. */
  961. public function getWhetherThisWindowMatchWindowExpression($currentWindowString, $target)
  962. {
  963. return $this->getBoolean("getWhetherThisWindowMatchWindowExpression", array($currentWindowString, $target));
  964. }
  965. /**
  966. * Waits for a popup window to appear and load up.
  967. *
  968. * @access public
  969. * @param string $windowID the JavaScript window ID of the window that will appear
  970. * @param string $timeout a timeout in milliseconds, after which the action will return with an error
  971. */
  972. public function waitForPopUp($windowID, $timeout)
  973. {
  974. $this->doCommand("waitForPopUp", array($windowID, $timeout));
  975. }
  976. /**
  977. * By default, Selenium's overridden window.confirm() function will
  978. * return true, as if the user had manually clicked OK; after running
  979. * this command, the next call to confirm() will return false, as if
  980. * the user had clicked Cancel. Selenium will then resume using the
  981. * default behavior for future confirmations, automatically returning
  982. * true (OK) unless/until you explicitly call this command for each
  983. * confirmation.
  984. *
  985. * @access public
  986. */
  987. public function chooseCancelOnNextConfirmation()
  988. {
  989. $this->doCommand("chooseCancelOnNextConfirmation", array());
  990. }
  991. /**
  992. * Undo the effect of calling chooseCancelOnNextConfirmation. Note
  993. * that Selenium's overridden window.confirm() function will normally automatically
  994. * return true, as if the user had manually clicked OK, so you shouldn't
  995. * need to use this command unless for some reason you need to change
  996. * your mind prior to the next confirmation. After any confirmation, Selenium will resume using the
  997. * default behavior for future confirmations, automatically returning
  998. * true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each
  999. * confirmation.
  1000. *
  1001. * @access public
  1002. */
  1003. public function chooseOkOnNextConfirmation()
  1004. {
  1005. $this->doCommand("chooseOkOnNextConfirmation", array());
  1006. }
  1007. /**
  1008. * Instructs Selenium to return the specified answer string in response to
  1009. * the next JavaScript prompt [window.prompt()].
  1010. *
  1011. * @access public
  1012. * @param string $answer the answer to give in response to the prompt pop-up
  1013. */
  1014. public function answerOnNextPrompt($answer)
  1015. {
  1016. $this->doCommand("answerOnNextPrompt", array($answer));
  1017. }
  1018. /**
  1019. * Simulates the user clicking the "back" button on their browser.
  1020. *
  1021. * @access public
  1022. */
  1023. public function goBack()
  1024. {
  1025. $this->doCommand("goBack", array());
  1026. }
  1027. /**
  1028. * Simulates the user clicking the "Refresh" button on their browser.
  1029. *
  1030. * @access public
  1031. */
  1032. public function refresh()
  1033. {
  1034. $this->doCommand("refresh", array());
  1035. }
  1036. /**
  1037. * Simulates the user clicking the "close" button in the titlebar of a popup
  1038. * window or tab.
  1039. *
  1040. * @access public
  1041. */
  1042. public function close()
  1043. {
  1044. $this->doCommand("close", array());
  1045. }
  1046. /**
  1047. * Has an alert occurred?
  1048. *
  1049. * <p>
  1050. *
  1051. * This function never throws an exception
  1052. *
  1053. * </p>
  1054. *
  1055. * @access public
  1056. * @return boolean true if there is an alert
  1057. */
  1058. public function isAlertPresent()
  1059. {
  1060. return $this->getBoolean("isAlertPresent", array());
  1061. }
  1062. /**
  1063. * Has a prompt occurred?
  1064. *
  1065. * <p>
  1066. *
  1067. * This function never throws an exception
  1068. *
  1069. * </p>
  1070. *
  1071. * @access public
  1072. * @return boolean true if there is a pending prompt
  1073. */
  1074. public function isPromptPresent()
  1075. {
  1076. return $this->getBoolean("isPromptPresent", array());
  1077. }
  1078. /**
  1079. * Has confirm() been called?
  1080. *
  1081. * <p>
  1082. *
  1083. * This function never throws an exception
  1084. *
  1085. * </p>
  1086. *
  1087. * @access public
  1088. * @return boolean true if there is a pending confirmation
  1089. */
  1090. public function isConfirmationPresent()
  1091. {
  1092. return $this->getBoolean("isConfirmationPresent", array());
  1093. }
  1094. /**
  1095. * Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
  1096. *
  1097. * <p>
  1098. * Getting an alert has the same effect as manually clicking OK. If an
  1099. * alert is generated but you do not get/verify it, the next Selenium action
  1100. * will fail.
  1101. * </p><p>
  1102. * NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
  1103. * dialog.
  1104. * </p><p>
  1105. * NOTE: Selenium does NOT support JavaScript alerts that are generated in a
  1106. * page's onload() event handler. In this case a visible dialog WILL be
  1107. * generated and Selenium will hang until someone manually clicks OK.
  1108. * </p>
  1109. *
  1110. * @access public
  1111. * @return string The message of the most recent JavaScript alert
  1112. */
  1113. public function getAlert()
  1114. {
  1115. return $this->getString("getAlert", array());
  1116. }
  1117. /**
  1118. * Retrieves the message of a JavaScript confirmation dialog generated during
  1119. * the previous action.
  1120. *
  1121. * <p>
  1122. *
  1123. * By default, the confirm function will return true, having the same effect
  1124. * as manually clicking OK. This can be changed by prior execution of the
  1125. * chooseCancelOnNextConfirmation command. If an confirmation is generated
  1126. * but you do not get/verify it, the next Selenium action will fail.
  1127. *
  1128. * </p><p>
  1129. *
  1130. * NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
  1131. * dialog.
  1132. *
  1133. * </p><p>
  1134. *
  1135. * NOTE: Selenium does NOT support JavaScript confirmations that are
  1136. * generated in a page's onload() event handler. In this case a visible
  1137. * dialog WILL be generated and Selenium will hang until you manually click
  1138. * OK.
  1139. *
  1140. * </p>
  1141. *
  1142. * @access public
  1143. * @return string the message of the most recent JavaScript confirmation dialog
  1144. */
  1145. public function getConfirmation()
  1146. {
  1147. return $this->getString("getConfirmation", array());
  1148. }
  1149. /**
  1150. * Retrieves the message of a JavaScript question prompt dialog generated during
  1151. * the previous action.
  1152. *
  1153. * <p>
  1154. * Successful handling of the prompt requires prior execution of the
  1155. * answerOnNextPrompt command. If a prompt is generated but you
  1156. * do not get/verify it, the next Selenium action will fail.
  1157. * </p><p>
  1158. * NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
  1159. * dialog.
  1160. * </p><p>
  1161. * NOTE: Selenium does NOT support JavaScript prompts that are generated in a
  1162. * page's onload() event handler. In this case a visible dialog WILL be
  1163. * generated and Selenium will hang until someone manually clicks OK.
  1164. * </p>
  1165. *
  1166. * @access public
  1167. * @return string the message of the most recent JavaScript question prompt
  1168. */
  1169. public function getPrompt()
  1170. {
  1171. return $this->getString("getPrompt", array());
  1172. }
  1173. /**
  1174. * Gets the absolute URL of the current page.
  1175. *
  1176. * @access public
  1177. * @return string the absolute URL of the current page
  1178. */
  1179. public function getLocation()
  1180. {
  1181. return $this->getString("getLocation", array());
  1182. }
  1183. /**
  1184. * Gets the title of the current page.
  1185. *
  1186. * @access public
  1187. * @return string the title of the current page
  1188. */
  1189. public function getTitle()
  1190. {
  1191. return $this->getString("getTitle", array());
  1192. }
  1193. /**
  1194. * Gets the entire text of the page.
  1195. *
  1196. * @access public
  1197. * @return string the entire text of the page
  1198. */
  1199. public function getBodyText()
  1200. {
  1201. return $this->getString("getBodyText", array());
  1202. }
  1203. /**
  1204. * Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
  1205. * For checkbox/radio elements, the value will be "on" or "off" depending on
  1206. * whether the element is checked or not.
  1207. *
  1208. * @access public
  1209. * @param string $locator an element locator
  1210. * @return string the element value, or "on/off" for checkbox/radio elements
  1211. */
  1212. public function getValue($locator)
  1213. {
  1214. return $this->getString("getValue", array($locator));
  1215. }
  1216. /**
  1217. * Gets the text of an element. This works for any element that contains
  1218. * text. This command uses either the textContent (Mozilla-like browsers) or
  1219. * the innerText (IE-like browsers) of the element, which is the rendered
  1220. * text shown to the user.
  1221. *
  1222. * @access public
  1223. * @param string $locator an element locator
  1224. * @return string the text of the element
  1225. */
  1226. public function getText($locator)
  1227. {
  1228. return $this->getString("getText", array($locator));
  1229. }
  1230. /**
  1231. * Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
  1232. *
  1233. * @access public
  1234. * @param string $locator an element locator
  1235. */
  1236. public function highlight($locator)
  1237. {
  1238. $this->doCommand("highlight", array($locator));
  1239. }
  1240. /**
  1241. * Gets the result of evaluating the specified JavaScript snippet. The snippet may
  1242. * have multiple lines, but only the result of the last line will be returned.
  1243. *
  1244. * <p>
  1245. * Note that, by default, the snippet will run in the context of the "selenium"
  1246. * object itself, so <code>this</code> will refer to the Selenium object. Use <code>window</code> to
  1247. * refer to the window of your application, e.g. <code>window.document.getElementById('foo')</code>
  1248. * </p><p>
  1249. * If you need to use
  1250. * a locator to refer to a single element in your application page, you can
  1251. * use <code>this.browserbot.findElement("id=foo")</code> where "id=foo" is your locator.
  1252. * </p>
  1253. *
  1254. * @access public
  1255. * @param string $script the JavaScript snippet to run
  1256. * @return string the results of evaluating the snippet
  1257. */
  1258. public function getEval($script)
  1259. {
  1260. return $this->getString("getEval", array($script));
  1261. }
  1262. /**
  1263. * Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
  1264. *
  1265. * @access public
  1266. * @param string $locator an element locator pointing to a checkbox or radio button
  1267. * @return boolean true if the checkbox is checked, false otherwise
  1268. */
  1269. public function isChecked($locator)
  1270. {
  1271. return $this->getBoolean("isChecked", array($locator));
  1272. }
  1273. /**
  1274. * Gets the text from a cell of a table. The cellAddress syntax
  1275. * tableLocator.row.column, where row and column start at 0.
  1276. *
  1277. * @access public
  1278. * @param string $tableCellAddress a cell address, e.g. "foo.1.4"
  1279. * @return string the text from the specified cell
  1280. */
  1281. public function getTable($tableCellAddress)
  1282. {
  1283. return $this->getString("getTable", array($tableCellAddress));
  1284. }
  1285. /**
  1286. * Gets all option labels (visible text) for selected options in the specified select or multi-select element.
  1287. *
  1288. * @access public
  1289. * @param string $selectLocator an element locator identifying a drop-down menu
  1290. * @return array an array of all selected option labels in the specified select drop-down
  1291. */
  1292. public function getSelectedLabels($selectLocator)
  1293. {
  1294. return $this->getStringArray("getSelectedLabels", array($selectLocator));
  1295. }
  1296. /**
  1297. * Gets option label (visible text) for selected option in the specified select element.
  1298. *
  1299. * @access public
  1300. * @param string $selectLocator an element locator identifying a drop-down menu
  1301. * @return string the selected option label in the specified select drop-down
  1302. */
  1303. public function getSelectedLabel($selectLocator)
  1304. {
  1305. return $this->getString("getSelectedLabel", array($selectLocator));
  1306. }
  1307. /**
  1308. * Gets all option values (value attributes) for selected options in the specified select or multi-select element.
  1309. *
  1310. * @access public
  1311. * @param string $selectLocator an element locator identifying a drop-down menu
  1312. * @return array an array of all selected option values in the specified select drop-down
  1313. */
  1314. public function getSelectedValues($selectLocator)
  1315. {
  1316. return $this->getStringArray("getSelectedValues", array($selectLocator));
  1317. }
  1318. /**
  1319. * Gets option value (value attribute) for selected option in the specified select element.
  1320. *
  1321. * @access public
  1322. * @param string $selectLocator an element locator identifying a drop-down menu
  1323. * @return string the selected option value in the specified select drop-down
  1324. */
  1325. public function getSelectedValue($selectLocator)
  1326. {
  1327. return $this->getString("getSelectedValue", array($selectLocator));
  1328. }
  1329. /**
  1330. * Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
  1331. *
  1332. * @access public
  1333. * @param string $selectLocator an element locator identifying a drop-down menu
  1334. * @return array an array of all selected option indexes in the specified select drop-down
  1335. */
  1336. public function getSelectedIndexes($selectLocator)
  1337. {
  1338. return $this->getStringArray("getSelectedIndexes", array($selectLocator));
  1339. }
  1340. /**
  1341. * Gets option index (option number, starting at 0) for selected option in the specified select element.
  1342. *
  1343. * @access public
  1344. * @param string $selectLocator an element locator identifying a drop-down menu
  1345. * @return string the selected option index in the specified select drop-down
  1346. */
  1347. public function getSelectedIndex($selectLocator)
  1348. {
  1349. return $this->getString("getSelectedIndex", array($selectLocator));
  1350. }
  1351. /**
  1352. * Gets all option element IDs for selected options in the specified select or multi-select element.
  1353. *
  1354. * @access public
  1355. * @param string $selectLocator an element locator identifying a drop-down menu
  1356. * @return array an array of all selected option IDs in the specified select drop-down
  1357. */
  1358. public function getSelectedIds($selectLocator)
  1359. {
  1360. return $this->getStringArray("getSelectedIds", array($selectLocator));
  1361. }
  1362. /**
  1363. * Gets option element ID for selected option in the specified select element.
  1364. *
  1365. * @access public
  1366. * @param string $selectLocator an element locator identifying a drop-down menu
  1367. * @return string the selected option ID in the specified select drop-down
  1368. */
  1369. public function getSelectedId($selectLocator)
  1370. {
  1371. return $this->getString("getSelectedId", array($selectLocator));
  1372. }
  1373. /**
  1374. * Determines whether some option in a drop-down menu is selected.
  1375. *
  1376. * @access public
  1377. * @param string $selectLocator an element locator identifying a drop-down menu
  1378. * @return boolean true if some option has been selected, false otherwise
  1379. */
  1380. public function isSomethingSelected($selectLocator)
  1381. {
  1382. return $this->getBoolean("isSomethingSelected", array($selectLocator));
  1383. }
  1384. /**
  1385. * Gets all option labels in the specified select drop-down.
  1386. *
  1387. * @access public
  1388. * @param string $selectLocator an element locator identifying a drop-down menu
  1389. * @return array an array of all option labels in the specified select drop-down
  1390. */
  1391. public function getSelectOptions($selectLocator)
  1392. {
  1393. return $this->getStringArray("getSelectOptions", array($selectLocator));
  1394. }
  1395. /**
  1396. * Gets the value of an element attribute.
  1397. *
  1398. * @access public
  1399. * @param string $attributeLocator an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"
  1400. * @return string the value of the specified attribute
  1401. */
  1402. public function getAttribute($attributeLocator)
  1403. {
  1404. return $this->getString("getAttribute", array($attributeLocator));
  1405. }
  1406. /**
  1407. * Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
  1408. *
  1409. * @access public
  1410. * @param string $pattern a pattern to match with the text of the page
  1411. * @return boolean true if the pattern matches the text, false otherwise
  1412. */
  1413. public function isTextPresent($pattern)
  1414. {
  1415. return $this->getBoolean("isTextPresent", array($pattern));
  1416. }
  1417. /**
  1418. * Verifies that the specified element is somewhere on the page.
  1419. *
  1420. * @access public
  1421. * @param string $locator an element locator
  1422. * @return boolean true if the element is present, false otherwise
  1423. */
  1424. public function isElementPresent($locator)
  1425. {
  1426. return $this->getBoolean("isElementPresent", array($locator));
  1427. }
  1428. /**
  1429. * Determines if the specified element is visible. An
  1430. * element can be rendered invisible by setting the CSS "visibility"
  1431. * property to "hidden", or the "display" property to "none", either for the
  1432. * element itself or one if its ancestors. This method will fail if
  1433. * the element is not present.
  1434. *
  1435. * @access public
  1436. * @param string $locator an element locator
  1437. * @return boolean true if the specified element is visible, false otherwise
  1438. */
  1439. public function isVisible($locator)
  1440. {
  1441. return $this->getBoolean("isVisible", array($locator));
  1442. }
  1443. /**
  1444. * Determines whether the specified input element is editable, ie hasn't been disabled.
  1445. * This method will fail if the specified element isn't an input element.
  1446. *
  1447. * @access public
  1448. * @param string $locator an element locator
  1449. * @return boolean true if the input element is editable, false otherwise
  1450. */
  1451. public function isEditable($locator)
  1452. {
  1453. return $this->getBoolean("isEditable", array($locator));
  1454. }
  1455. /**
  1456. * Returns the IDs of all buttons on the page.
  1457. *
  1458. * <p>
  1459. * If a given button has no ID, it will appear as "" in this array.
  1460. * </p>
  1461. *
  1462. * @access public
  1463. * @return array the IDs of all buttons on the page
  1464. */
  1465. public function getAllButtons()
  1466. {
  1467. return $this->getStringArray("getAllButtons", array());
  1468. }
  1469. /**
  1470. * Returns the IDs of all links on the page.
  1471. *
  1472. * <p>
  1473. * If a given link has no ID, it will appear as "" in this array.
  1474. * </p>
  1475. *
  1476. * @access public
  1477. * @return array the IDs of all links on the page
  1478. */
  1479. public function getAllLinks()
  1480. {
  1481. return $this->getStringArray("getAllLinks", array());
  1482. }
  1483. /**
  1484. * Returns the IDs of all input fields on the page.
  1485. *
  1486. * <p>
  1487. * If a given field has no ID, it will appear as "" in this array.
  1488. * </p>
  1489. *
  1490. * @access public
  1491. * @return array the IDs of all field on the page
  1492. */
  1493. public function getAllFields()
  1494. {
  1495. return $this->getStringArray("getAllFields", array());
  1496. }
  1497. /**
  1498. * Returns every instance of some attribute from all known windows.
  1499. *
  1500. * @access public
  1501. * @param string $attributeName name of an attribute on the windows
  1502. * @return array the set of values of this attribute from all known windows.
  1503. */
  1504. public function getAttributeFromAllWindows($attributeName)
  1505. {
  1506. return $this->getStringArray("getAttributeFromAllWindows", array($attributeName));
  1507. }
  1508. /**
  1509. * deprecated - use dragAndDrop instead
  1510. *
  1511. * @access public
  1512. * @param string $locator an element locator
  1513. * @param string $movementsString offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
  1514. */
  1515. public function dragdrop($locator, $movementsString)
  1516. {
  1517. $this->doCommand("dragdrop", array($locator, $movementsString));
  1518. }
  1519. /**
  1520. * Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
  1521. * <p>
  1522. * Setting this value to 0 means that we'll send a "mousemove" event to every single pixel
  1523. * in between the start location and the end location; that can be very slow, and may
  1524. * cause some browsers to force the JavaScript to timeout.
  1525. * </p><p>
  1526. * If the mouse speed is greater than the distance between the two dragged objects, we'll
  1527. * just send one "mousemove" at the start location and then one final one at the end location.
  1528. * </p>
  1529. *
  1530. * @access public
  1531. * @param string $pixels the number of pixels between "mousemove" events
  1532. */
  1533. public function setMouseSpeed($pixels)
  1534. {
  1535. $this->doCommand("setMouseSpeed", array($pixels));
  1536. }
  1537. /**
  1538. * Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
  1539. *
  1540. * @access public
  1541. * @return number the number of pixels between "mousemove" events during dragAndDrop commands (default=10)
  1542. */
  1543. public function getMouseSpeed()
  1544. {
  1545. return $this->getNumber("getMouseSpeed", array());
  1546. }
  1547. /**
  1548. * Drags an element a certain distance and then drops it
  1549. *
  1550. * @access public
  1551. * @param string $locator an element locator
  1552. * @param string $movementsString offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
  1553. */
  1554. public function dragAndDrop($locator, $movementsString)
  1555. {
  1556. $this->doCommand("dragAndDrop", array($locator, $movementsString));
  1557. }
  1558. /**
  1559. * Drags an element and drops it on another element
  1560. *
  1561. * @access public
  1562. * @param string $locatorOfObjectToBeDragged an element to be dragged
  1563. * @param string $locatorOfDragDestinationObject an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
  1564. */
  1565. public function dragAndDropToObject($locatorOfObjectToBeDragged, $locatorOfDragDestinationObject)
  1566. {
  1567. $this->doCommand("dragAndDropToObject", array($locatorOfObjectToBeDragged, $locatorOfDragDestinationObject));
  1568. }
  1569. /**
  1570. * Gives focus to the currently selected window
  1571. *
  1572. * @access public
  1573. */
  1574. public function windowFocus()
  1575. {
  1576. $this->doCommand("windowFocus", array());
  1577. }
  1578. /**
  1579. * Resize currently selected window to take up the entire screen
  1580. *
  1581. * @access public
  1582. */
  1583. public function windowMaximize()
  1584. {
  1585. $this->doCommand("windowMaximize", array());
  1586. }
  1587. /**
  1588. * Returns the IDs of all windows that the browser knows about.
  1589. *
  1590. * @access public
  1591. * @return array the IDs of all windows that the browser knows about.
  1592. */
  1593. public function getAllWindowIds()
  1594. {
  1595. return $this->getStringArray("getAllWindowIds", array());
  1596. }
  1597. /**
  1598. * Returns the names of all windows that the browser knows about.
  1599. *
  1600. * @access public
  1601. * @return array the names of all windows that the browser knows about.
  1602. */
  1603. public function getAllWindowNames()
  1604. {
  1605. return $this->getStringArray("getAllWindowNames", array());
  1606. }
  1607. /**
  1608. * Returns the titles of all windows that the browser knows about.
  1609. *
  1610. * @access public
  1611. * @return array the titles of all windows that the browser knows about.
  1612. */
  1613. public function getAllWindowTitles()
  1614. {
  1615. return $this->getStringArray("getAllWindowTitles", array());
  1616. }
  1617. /**
  1618. * Returns the entire HTML source between the opening and
  1619. * closing "html" tags.
  1620. *
  1621. * @access public
  1622. * @return string the entire HTML source
  1623. */
  1624. public function getHtmlSource()
  1625. {
  1626. return $this->getString("getHtmlSource", array());
  1627. }
  1628. /**
  1629. * Moves the text cursor to the specified position in the given input element or textarea.
  1630. * This method will fail if the specified element isn't an input element or textarea.
  1631. *
  1632. * @access public
  1633. * @param string $locator an element locator pointing to an input element or textarea
  1634. * @param string $position 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.
  1635. */
  1636. public function setCursorPosition($locator, $position)
  1637. {
  1638. $this->doCommand("setCursorPosition", array($locator, $position));
  1639. }
  1640. /**
  1641. * Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
  1642. * will be ignored.
  1643. *
  1644. * @access public
  1645. * @param string $locator an element locator pointing to an element
  1646. * @return number of relative index of the element to its parent (starting from 0)
  1647. */
  1648. public function getElementIndex($locator)
  1649. {
  1650. return $this->getNumber("getElementIndex", array($locator));
  1651. }
  1652. /**
  1653. * Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will
  1654. * not be considered ordered.
  1655. *
  1656. * @access public
  1657. * @param string $locator1 an element locator pointing to the first element
  1658. * @param string $locator2 an element locator pointing to the second element
  1659. * @return boolean true if element1 is the previous sibling of element2, false otherwise
  1660. */
  1661. public function isOrdered($locator1, $locator2)
  1662. {
  1663. return $this->getBoolean("isOrdered", array($locator1, $locator2));
  1664. }
  1665. /**
  1666. * Retrieves the horizontal position of an element
  1667. *
  1668. * @access public
  1669. * @param string $locator an element locator pointing to an element OR an element itself
  1670. * @return number of pixels from the edge of the frame.
  1671. */
  1672. public function getElementPositionLeft($locator)
  1673. {
  1674. return $this->getNumber("getElementPositionLeft", array($locator));
  1675. }
  1676. /**
  1677. * Retrieves the vertical position of an element
  1678. *
  1679. * @access public
  1680. * @param string $locator an element locator pointing to an element OR an element itself
  1681. * @return number of pixels from the edge of the frame.
  1682. */
  1683. public function getElementPositionTop($locator)
  1684. {
  1685. return $this->getNumber("getElementPositionTop", array($locator));
  1686. }
  1687. /**
  1688. * Retrieves the width of an element
  1689. *
  1690. * @access public
  1691. * @param string $locator an element locator pointing to an element
  1692. * @return number width of an element in pixels
  1693. */
  1694. public function getElementWidth($locator)
  1695. {
  1696. return $this->getNumber("getElementWidth", array($locator));
  1697. }
  1698. /**
  1699. * Retrieves the height of an element
  1700. *
  1701. * @access public
  1702. * @param string $locator an element locator pointing to an element
  1703. * @return number height of an element in pixels
  1704. */
  1705. public function getElementHeight($locator)
  1706. {
  1707. return $this->getNumber("getElementHeight", array($locator));
  1708. }
  1709. /**
  1710. * Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
  1711. *
  1712. * <p>
  1713. * Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
  1714. * 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.
  1715. * </p>
  1716. * This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
  1717. *
  1718. * @access public
  1719. * @param string $locator an element locator pointing to an input element or textarea
  1720. * @return number the numerical position of the cursor in the field
  1721. */
  1722. public function getCursorPosition($locator)
  1723. {
  1724. return $this->getNumber("getCursorPosition", array($locator));
  1725. }
  1726. /**
  1727. * Returns the specified expression.
  1728. *
  1729. * <p>
  1730. * This is useful because of JavaScript preprocessing.
  1731. * It is used to generate commands like assertExpression and waitForExpression.
  1732. * </p>
  1733. *
  1734. * @access public
  1735. * @param string $expression the value to return
  1736. * @return string the value passed in
  1737. */
  1738. public function getExpression($expression)
  1739. {
  1740. return $this->getString("getExpression", array($expression));
  1741. }
  1742. /**
  1743. * Returns the number of nodes that match the specified xpath, eg. "//table" would give
  1744. * the number of tables.
  1745. *
  1746. * @access public
  1747. * @param string $xpath the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
  1748. * @return number the number of nodes that match the specified xpath
  1749. */
  1750. public function getXpathCount($xpath)
  1751. {
  1752. return $this->getNumber("getXpathCount", array($xpath));
  1753. }
  1754. /**
  1755. * Temporarily sets the "id" attribute of the specified element, so you can locate it in the future
  1756. * using its ID rather than a slow/complicated XPath. This ID will disappear once the page is
  1757. * reloaded.
  1758. *
  1759. * @access public
  1760. * @param string $locator an element locator pointing to an element
  1761. * @param string $identifier a string to be used as the ID of the specified element
  1762. */
  1763. public function assignId($locator, $identifier)
  1764. {
  1765. $this->doCommand("assignId", array($locator, $identifier));
  1766. }
  1767. /**
  1768. * Specifies whether Selenium should use the native in-browser implementation
  1769. * of XPath (if any native version is available); if you pass "false" to
  1770. * this function, we will always use our pure-JavaScript xpath library.
  1771. * Using the pure-JS xpath library can improve the consistency of xpath
  1772. * element locators between different browser vendors, but the pure-JS
  1773. * version is much slower than the native implementations.
  1774. *
  1775. * @access public
  1776. * @param string $allow boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
  1777. */
  1778. public function allowNativeXpath($allow)
  1779. {
  1780. $this->doCommand("allowNativeXpath", array($allow));
  1781. }
  1782. /**
  1783. * Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
  1784. * The snippet may have multiple lines, but only the result of the last line
  1785. * will be considered.
  1786. *
  1787. * <p>
  1788. * Note that, by default, the snippet will be run in the runner's test window, not in the window
  1789. * of your application. To get the window of your application, you can use
  1790. * the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
  1791. * run your JavaScript in there
  1792. * </p>
  1793. *
  1794. * @access public
  1795. * @param string $script the JavaScript snippet to run
  1796. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1797. */
  1798. public function waitForCondition($script, $timeout)
  1799. {
  1800. $this->doCommand("waitForCondition", array($script, $timeout));
  1801. }
  1802. /**
  1803. * Specifies the amount of time that Selenium will wait for actions to complete.
  1804. *
  1805. * <p>
  1806. * Actions that require waiting include "open" and the "waitFor*" actions.
  1807. * </p>
  1808. * The default timeout is 30 seconds.
  1809. *
  1810. * @access public
  1811. * @param string $timeout a timeout in milliseconds, after which the action will return with an error
  1812. */
  1813. public function setTimeout($timeout)
  1814. {
  1815. $this->doCommand("setTimeout", array($timeout));
  1816. }
  1817. /**
  1818. * Waits for a new page to load.
  1819. *
  1820. * <p>
  1821. * You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
  1822. * (which are only available in the JS API).
  1823. * </p><p>
  1824. * Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
  1825. * flag when it first notices a page load. Running any other Selenium command after
  1826. * turns the flag to false. Hence, if you want to wait for a page to load, you must
  1827. * wait immediately after a Selenium command that caused a page-load.
  1828. * </p>
  1829. *
  1830. * @access public
  1831. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1832. */
  1833. public function waitForPageToLoad($timeout)
  1834. {
  1835. $this->doCommand("waitForPageToLoad", array($timeout));
  1836. }
  1837. /**
  1838. * Waits for a new frame to load.
  1839. *
  1840. * <p>
  1841. * Selenium constantly keeps track of new pages and frames loading,
  1842. * and sets a "newPageLoaded" flag when it first notices a page load.
  1843. * </p>
  1844. *
  1845. * See waitForPageToLoad for more information.
  1846. *
  1847. * @access public
  1848. * @param string $frameAddress FrameAddress from the server side
  1849. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1850. */
  1851. public function waitForFrameToLoad($frameAddress, $timeout)
  1852. {
  1853. $this->doCommand("waitForFrameToLoad", array($frameAddress, $timeout));
  1854. }
  1855. /**
  1856. * Return all cookies of the current page under test.
  1857. *
  1858. * @access public
  1859. * @return string all cookies of the current page under test
  1860. */
  1861. public function getCookie()
  1862. {
  1863. return $this->getString("getCookie", array());
  1864. }
  1865. /**
  1866. * Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
  1867. *
  1868. * @access public
  1869. * @param string $name the name of the cookie
  1870. * @return string the value of the cookie
  1871. */
  1872. public function getCookieByName($name)
  1873. {
  1874. return $this->getString("getCookieByName", array($name));
  1875. }
  1876. /**
  1877. * Returns true if a cookie with the specified name is present, or false otherwise.
  1878. *
  1879. * @access public
  1880. * @param string $name the name of the cookie
  1881. * @return boolean true if a cookie with the specified name is present, or false otherwise.
  1882. */
  1883. public function isCookiePresent($name)
  1884. {
  1885. return $this->getBoolean("isCookiePresent", array($name));
  1886. }
  1887. /**
  1888. * Create a new cookie whose path and domain are same with those of current page
  1889. * under test, unless you specified a path for this cookie explicitly.
  1890. *
  1891. * @access public