* Treat this element as an iframe; invoke `fn` with a WebElement wrapping * the iframe body. For WebDriver this switches the browser into the frame * for the duration of the callback and switches back on exit. * @param {(body: WebElement) => Promise } fn * @returns {Promise } Ret
(fn)
| 365 | * @returns {Promise<any>} Return value of fn |
| 366 | */ |
| 367 | async inIframe(fn) { |
| 368 | switch (this.helperType) { |
| 369 | case 'playwright': |
| 370 | case 'puppeteer': { |
| 371 | const frame = await this.element.contentFrame() |
| 372 | const body = await frame.$('body') |
| 373 | return fn(new WebElement(body, this.helper)) |
| 374 | } |
| 375 | case 'webdriver': { |
| 376 | const browser = this.helper.browser |
| 377 | await browser.switchFrame(this.element) |
| 378 | try { |
| 379 | const body = await browser.$('body') |
| 380 | return await fn(new WebElement(body, this.helper)) |
| 381 | } finally { |
| 382 | await browser.switchFrame(null) |
| 383 | } |
| 384 | } |
| 385 | default: |
| 386 | throw new Error(`Unsupported helper type: ${this.helperType}`) |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Find first child element matching the locator |
no test coverage detected