Skip to content

Commit 4e171e6

Browse files
committed
create LegacyElement (similar to LegacyWindow)
1 parent 225f50a commit 4e171e6

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

lib/WebDriver/Container.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
*/
3434
abstract class Container extends AbstractWebDriver
3535
{
36-
const LEGACY_ELEMENT_ID = 'ELEMENT';
37-
const WEB_ELEMENT_ID = 'element-6066-11e4-a52e-4f735466cecf';
38-
3936
/**
4037
* @var array
4138
*/
@@ -212,22 +209,18 @@ public function locate($using, $value)
212209
*/
213210
protected function webDriverElement($value)
214211
{
215-
if (array_key_exists(self::LEGACY_ELEMENT_ID, (array) $value)) {
216-
assert($this->legacy === false);
217-
218-
return new Element(
219-
$this->getElementPath($value[self::LEGACY_ELEMENT_ID]), // url
220-
$value[self::LEGACY_ELEMENT_ID], // id
212+
if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, (array) $value)) {
213+
return new LegacyElement(
214+
$this->getElementPath($value[LegacyElement::LEGACY_ELEMENT_ID]), // url
215+
$value[LegacyElement::LEGACY_ELEMENT_ID], // id
221216
$this->legacy
222217
);
223218
}
224219

225-
if (array_key_exists(self::WEB_ELEMENT_ID, (array) $value)) {
226-
assert($this->legacy === true);
227-
220+
if (array_key_exists(Element::WEB_ELEMENT_ID, (array) $value)) {
228221
return new Element(
229-
$this->getElementPath($value[self::WEB_ELEMENT_ID]), // url
230-
$value[self::WEB_ELEMENT_ID], // id
222+
$this->getElementPath($value[Element::WEB_ELEMENT_ID]), // url
223+
$value[Element::WEB_ELEMENT_ID], // id
231224
$this->legacy
232225
);
233226
}

lib/WebDriver/Element.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
* @method string text() Returns the visible text for the element.
4848
* @method void postValue($json) Send a sequence of key strokes to an element.
4949
*/
50-
final class Element extends Container
50+
class Element extends Container
5151
{
52+
const WEB_ELEMENT_ID = 'element-6066-11e4-a52e-4f735466cecf';
53+
5254
/**
5355
* {@inheritdoc}
5456
*/

lib/WebDriver/Execute.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ private function serializeArguments(array $arguments)
8282
{
8383
foreach ($arguments as $key => $value) {
8484
switch (true) {
85+
case $value instanceof LegacyElement:
86+
$arguments[$key] = [LegacyElement::LEGACY_ELEMENT_ID => $value->getID()];
87+
break;
88+
8589
case $value instanceof Element:
86-
$arguments[$key] = [$this->isLegacy() ? Container::LEGACY_ELEMENT_ID : Container::WEB_ELEMENT_ID => $value->getID()];
90+
$arguments[$key] = [Element::WEB_ELEMENT_ID => $value->getID()];
8791
break;
8892

8993
case $value instanceof Shadow:
@@ -134,18 +138,18 @@ protected function webDriverElement($value)
134138
{
135139
$basePath = preg_replace('~/execute$~', '', $this->url);
136140

137-
if (array_key_exists(Container::LEGACY_ELEMENT_ID, $value)) {
138-
return new Element(
139-
$basePath . '/element/' . $value[Container::LEGACY_ELEMENT_ID], // url
140-
$value[Container::LEGACY_ELEMENT_ID], // id
141+
if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, $value)) {
142+
return new LegacyElement(
143+
$basePath . '/element/' . $value[LegacyElement::LEGACY_ELEMENT_ID], // url
144+
$value[LegacyElement::LEGACY_ELEMENT_ID], // id
141145
$this->legacy
142146
);
143147
}
144148

145-
if (array_key_exists(Container::WEB_ELEMENT_ID, $value)) {
149+
if (array_key_exists(Element::WEB_ELEMENT_ID, $value)) {
146150
return new Element(
147-
$basePath . '/element/' . $value[Container::WEB_ELEMENT_ID], // url
148-
$value[Container::WEB_ELEMENT_ID], // id
151+
$basePath . '/element/' . $value[Element::WEB_ELEMENT_ID], // url
152+
$value[Element::WEB_ELEMENT_ID], // id
149153
$this->legacy
150154
);
151155
}

lib/WebDriver/LegacyElement.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022-2022 Anthon Pang. All Rights Reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package WebDriver
19+
*
20+
* @author Anthon Pang <apang@softwaredevelopment.ca>
21+
*/
22+
23+
namespace WebDriver;
24+
25+
/**
26+
* WebDriver\LegacyElement class
27+
*
28+
* @package WebDriver
29+
*
30+
* @method string attribute($attributeName) Get the value of an element's attribute.
31+
* @method void clear() Clear a TEXTAREA or text INPUT element's value.
32+
* @method void click() Click on an element.
33+
* @method string css($propertyName) Query the value of an element's computed CSS property.
34+
* @method boolean displayed() Determine if an element is currently displayed.
35+
* @method boolean enabled() Determine if an element is currently enabled.
36+
* @method boolean equals($otherId) Test if two element IDs refer to the same DOM element.
37+
* @method array location() Determine an element's location on the page.
38+
* @method array location_in_view() Determine an element's location on the screen once it has been scrolled into view.
39+
* @method string name() Query for an element's tag name.
40+
* @method array property($propertyName) Get Element Property
41+
* @method array rect() Get Element Rect
42+
* @method array screenshot() Take Element Screenshot
43+
* @method array size() Determine an element's size in pixels.
44+
* @method void submit() Submit a FORM element.
45+
* @method string text() Returns the visible text for the element.
46+
* @method void postValue($json) Send a sequence of key strokes to an element.
47+
*/
48+
class LegacyElement extends Element
49+
{
50+
const LEGACY_ELEMENT_ID = 'ELEMENT';
51+
}

0 commit comments

Comments
 (0)