Skip to content

[🐛 Bug]: switchFrame(url) and switchFrame(function) fail when the iframe does not exist yet #14499

@htho

Description

@htho

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.14.0

Node.js Version

v22.13.1

Mode

WDIO Testrunner

Which capabilities are you using?

{
    browserName: 'chrome',
},
{
    browserName: 'firefox',
},

What happened?

I have an Iframe that is inserted to the dom at some point.
I use browser.switchFrame to switch to that iframe.

Since #14082 switchFrame waits for the iframe element to appear. But it does not work with urls or functions.

Here is a test-case:

import { expect, browser, $ } from '@wdio/globals'

beforeEach(async () => {
    await browser.url(`https://htho.github.io/wdio-repro-collection/delayedIframe.html`)
});

describe('switchFrame', () => {
    it(`can take a selector of a delayed iframe (works in 9.14.0)`, async () => {
        await browser.switchFrame($(`#delayedIframe`));
        await expect($(`h1`)).toHaveText("Delayed Inner Iframe");
    });
    it(`can take an url of a delayed iframe (fails in 9.14.0)`, async () => {
        await browser.switchFrame(`https://htho.github.io/wdio-repro-collection/delayedIframeInner.html`);
        await expect($(`h1`)).toHaveText("Delayed Inner Iframe");
    });
    it(`can take a function to identify a delayed iframe (fails in 9.14.0)`, async () => {
        await browser.switchFrame(() => document.URL.includes('delayedIframeInner'));
        await expect($(`h1`)).toHaveText("Delayed Inner Iframe");
    });
});

What is your expected behavior?

All three tests should pass.

How to reproduce the bug.

I created a repository that I reuse to report bugs: https://github.com/htho/wdio-repro-collection

  1. git clone https://github.com/htho/wdio-repro-collection.git
  2. cd wdio-repro-collection
  3. npm ci
  4. npm run test:delayedIframe

Relevant log output

nothing special

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions