File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments