Skip to content

Commit 107285a

Browse files
authored
Iframe improvements (#5454)
* Removed AngularJS module * WebDriver: switchToIframe to be used with CSS/XPath
1 parent cf74336 commit 107285a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Codeception/Module/WebDriver.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,16 @@ public function switchToIFrame($name = null)
25242524
$this->webDriver->switchTo()->defaultContent();
25252525
return;
25262526
}
2527-
$this->webDriver->switchTo()->frame($name);
2527+
try {
2528+
$this->webDriver->switchTo()->frame($name);
2529+
} catch (\Exception $e) {
2530+
$this->debug('Iframe was not found by name, locating iframe by CSS or XPath');
2531+
$frames = $this->_findElements($name);
2532+
if (!count($frames)) {
2533+
throw $e;
2534+
}
2535+
$this->webDriver->switchTo()->frame($frames[0]);
2536+
}
25282537
}
25292538

25302539
/**

tests/web/WebDriverTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,11 @@ public function testSwitchToIframe()
10811081
$this->module->see('Lots of valuable data here');
10821082
$this->module->switchToIFrame();
10831083
$this->module->see('Iframe test');
1084+
$this->module->switchToIFrame('iframe');
1085+
$this->module->see('Lots of valuable data here');
1086+
$this->module->switchToIFrame();
1087+
$this->module->see('Iframe test');
1088+
10841089
}
10851090

10861091
public function testGrabPageSourceWhenNotOnPage()

0 commit comments

Comments
 (0)