Element.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright 2004-2017 Facebook. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * @package WebDriver
  18. *
  19. * @author Justin Bishop <jubishop@gmail.com>
  20. * @author Anthon Pang <apang@softwaredevelopment.ca>
  21. * @author Fabrizio Branca <mail@fabrizio-branca.de>
  22. */
  23. namespace WebDriver;
  24. /**
  25. * WebDriver\Element class
  26. *
  27. * @package WebDriver
  28. *
  29. * @method void click() Click on an element.
  30. * @method void submit() Submit a FORM element.
  31. * @method string text() Returns the visible text for the element.
  32. * @method void postValue($json) Send a sequence of key strokes to an element.
  33. * @method string name() Query for an element's tag name.
  34. * @method void clear() Clear a TEXTAREA or text INPUT element's value.
  35. * @method boolean selected() Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected.
  36. * @method boolean enabled() Determine if an element is currently enabled.
  37. * @method string attribute($attributeName) Get the value of an element's attribute.
  38. * @method boolean equals($otherId) Test if two element IDs refer to the same DOM element.
  39. * @method boolean displayed() Determine if an element is currently displayed.
  40. * @method array location() Determine an element's location on the page.
  41. * @method array location_in_view() Determine an element's location on the screen once it has been scrolled into view.
  42. * @method array size() Determine an element's size in pixels.
  43. * @method string css($propertyName) Query the value of an element's computed CSS property.
  44. */
  45. final class Element extends Container
  46. {
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function methods()
  51. {
  52. return array(
  53. 'click' => array('POST'),
  54. 'submit' => array('POST'),
  55. 'text' => array('GET'),
  56. 'value' => array('POST'),
  57. 'name' => array('GET'),
  58. 'clear' => array('POST'),
  59. 'selected' => array('GET'),
  60. 'enabled' => array('GET'),
  61. 'attribute' => array('GET'),
  62. 'equals' => array('GET'),
  63. 'displayed' => array('GET'),
  64. 'location' => array('GET'),
  65. 'location_in_view' => array('GET'),
  66. 'size' => array('GET'),
  67. 'css' => array('GET'),
  68. );
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. protected function obsoleteMethods()
  74. {
  75. return array(
  76. 'value' => array('GET'),
  77. 'selected' => array('POST'),
  78. 'toggle' => array('POST'),
  79. 'hover' => array('POST'),
  80. 'drag' => array('POST'),
  81. );
  82. }
  83. /**
  84. * Element ID
  85. *
  86. * @var string
  87. */
  88. private $id;
  89. /**
  90. * Constructor
  91. *
  92. * @param string $url URL
  93. * @param string $id element ID
  94. */
  95. public function __construct($url, $id)
  96. {
  97. parent::__construct($url);
  98. $this->id = $id;
  99. }
  100. /**
  101. * Get element ID
  102. *
  103. * @return string
  104. */
  105. public function getID()
  106. {
  107. return $this->id;
  108. }
  109. /**
  110. * {@inheritdoc}
  111. */
  112. protected function getElementPath($elementId)
  113. {
  114. return preg_replace(sprintf('/%s$/', $this->id), $elementId, $this->url);
  115. }
  116. }