Skip to content

Commit 7e6de3f

Browse files
eXorusNaktibalda
authored andcommitted
Updated switchToIFrame by name to work in w3c mode
1 parent aa7c2d6 commit 7e6de3f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Codeception/Module/WebDriver.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,37 +2521,39 @@ public function switchToWindow($name = null)
25212521
*
25222522
* Example:
25232523
* ``` html
2524-
* <iframe name="another_frame" src="http://example.com">
2524+
* <iframe name="another_frame" id="fr1" src="http://example.com">
25252525
*
25262526
* ```
25272527
*
25282528
* ``` php
25292529
* <?php
2530-
* # switch to iframe
2530+
* # switch to iframe by name
25312531
* $I->switchToIFrame("another_frame");
2532+
* # switch to iframe by CSS or XPath
2533+
* $I->switchToIFrame("#fr1");
25322534
* # switch to parent page
25332535
* $I->switchToIFrame();
25342536
*
25352537
* ```
25362538
*
2537-
* @param string|null $name
2539+
* @param string|null $locator (name, CSS or XPath)
25382540
*/
2539-
public function switchToIFrame($name = null)
2541+
public function switchToIFrame($locator = null)
25402542
{
2541-
if (is_null($name)) {
2543+
if (is_null($locator)) {
25422544
$this->webDriver->switchTo()->defaultContent();
25432545
return;
25442546
}
25452547
try {
2546-
$this->webDriver->switchTo()->frame($name);
2548+
$els = $this->_findElements("iframe[name='$locator']");
25472549
} catch (\Exception $e) {
25482550
$this->debug('Iframe was not found by name, locating iframe by CSS or XPath');
2549-
$frames = $this->_findElements($name);
2550-
if (!count($frames)) {
2551-
throw $e;
2552-
}
2553-
$this->webDriver->switchTo()->frame($frames[0]);
2551+
$els = $this->_findElements($locator);
2552+
}
2553+
if (!count($els)) {
2554+
throw new ElementNotFound($selector, "Iframe was not found by CSS or XPath");
25542555
}
2556+
$this->webDriver->switchTo()->frame($els[0]);
25552557
}
25562558

25572559
/**

0 commit comments

Comments
 (0)