Skip to content

Commit 83d7869

Browse files
committed
Fix implementation of /session/:sessionid/element/:elementid/shadow
1 parent 51ae1a9 commit 83d7869

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

lib/WebDriver/Element.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,25 @@ public function getID()
132132
* shadow root method chaining, e.g.,
133133
* - $element->method()
134134
*
135-
* @return \WebDriver\Shadow
135+
* @return \WebDriver\Shadow|null
136136
*
137137
*/
138138
public function shadow()
139139
{
140-
return new Shadow($this->url . '/shadow', $this->legacy);
140+
$result = $this->curl('POST', '/shadow');
141+
$value = $result['value'];
142+
143+
if (array_key_exists(Shadow::SHADOW_ROOT_ID, (array) $value)) {
144+
$shadowRootReference = $value[Shadow::SHADOW_ROOT_ID];
145+
146+
return new Shadow(
147+
preg_replace('/element/' . preg_quote($this->id, '/') . '$/', '/', $this->url), // remove /element/:elementid
148+
$shadowRootReference,
149+
$this->legacy
150+
);
151+
}
152+
153+
return null;
141154
}
142155

143156
/**

lib/WebDriver/Shadow.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,42 @@ protected function methods()
4141
return array();
4242
}
4343

44+
/**
45+
* Shadow ID
46+
*
47+
* @var string
48+
*/
49+
private $id;
50+
51+
/**
52+
* Constructor
53+
*
54+
* @param string $url URL
55+
* @param string $id shadow ID
56+
* @param boolean $legacy Is legacy?
57+
*/
58+
public function __construct($url, $id, $legacy)
59+
{
60+
parent::__construct($url, $legacy);
61+
62+
$this->id = $id;
63+
}
64+
65+
/**
66+
* Get shadow ID
67+
*
68+
* @return string
69+
*/
70+
public function getID()
71+
{
72+
return $this->id;
73+
}
74+
4475
/**
4576
* {@inheritdoc}
4677
*/
47-
protected function getElementPath($elementId)
78+
protected function getElementPath($shadowId)
4879
{
49-
return sprintf('%s/element/%s', $this->url, $elementId);
80+
return sprintf('%s/shadow/%s', $this->url, $shadowId);
5081
}
5182
}

0 commit comments

Comments
 (0)