Skip to content

Commit ae9a5bf

Browse files
author
whhone
committed
[switchTo] switch to frame by WebDriverElement
Allow switching to a frame by the WebDriverElement. Sample: $frame_element = $driver->findElement($by); $driver->switchTo()->frame($frame_element);
1 parent d08a0c1 commit ae9a5bf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/WebDriverTargetLocator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ public function defaultContent() {
4141
/**
4242
* Switch to the iframe by its id or name.
4343
*
44+
* @param WebDriverElement|string $frame The WebDriverElement,
45+
the id or the name of the frame.
4446
* @return WebDriver The driver focused on the given frame.
4547
*/
46-
public function frame($id_or_name) {
47-
$params = array('id' => (string)$id_or_name);
48+
public function frame($frame) {
49+
if ($frame instanceof WebDriverElement) {
50+
$id = array('ELEMENT' => $frame->getID());
51+
} else {
52+
$id = (string)$frame;
53+
}
54+
55+
$params = array('id' => $id);
4856
$this->executor->execute('focusFrame', $params);
4957

5058
return $this->driver;

0 commit comments

Comments
 (0)