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