* {{> switchTo }}
(locator)
| 2660 | * {{> switchTo }} |
| 2661 | */ |
| 2662 | async switchTo(locator) { |
| 2663 | if (Number.isInteger(locator)) { |
| 2664 | // Select by frame index of current context |
| 2665 | let frames = [] |
| 2666 | if (this.context && typeof this.context.childFrames === 'function') { |
| 2667 | frames = await this.context.childFrames() |
| 2668 | } else { |
| 2669 | frames = await this.page.mainFrame().childFrames() |
| 2670 | } |
| 2671 | |
| 2672 | if (locator >= 0 && locator < frames.length) { |
| 2673 | this.context = frames[locator] |
| 2674 | } else { |
| 2675 | throw new Error('Frame index out of bounds') |
| 2676 | } |
| 2677 | return |
| 2678 | } |
| 2679 | |
| 2680 | if (!locator) { |
| 2681 | this.context = await this.page.mainFrame() |
| 2682 | return |
| 2683 | } |
| 2684 | |
| 2685 | // Select iframe by selector |
| 2686 | const els = await this._locate(locator) |
| 2687 | assertElementExists(els, locator) |
| 2688 | |
| 2689 | const iframeElement = els[0] |
| 2690 | const contentFrame = await iframeElement.contentFrame() |
| 2691 | |
| 2692 | if (contentFrame) { |
| 2693 | this.context = contentFrame |
| 2694 | } else { |
| 2695 | throw new Error('Element "#invalidIframeSelector" was not found by text|CSS|XPath') |
| 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | /** |
| 2700 | * {{> waitForFunction }} |
no test coverage detected