Skip to content

[🐛 Bug]: Can't switchFrame to an iframe in a Shadow DOM #14514

@htho

Description

@htho

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.14.0

Node.js Version

22.13.1

Mode

WDIO Testrunner

Which capabilities are you using?

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

What happened?

I created a repository where I reproduce wdio bugs: https://github.com/htho/wdio-repro-collection

I want to switchFrame to an iframe in a shadow dom. But it fails (see below)

What is your expected behavior?

It should be possible to switch to an iframe even if it is in a shadow root.

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:iframeInShadow
<!-- https://htho.github.io/wdio-repro-collection/iframeInShadow.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IFrame in Shadow DOM</title>
</head>
<body>
    <h1>IFrame in Shadow DOM</h1>
    <div id="wrapper">
        <template shadowrootmode="open">
            <h2 id="headlineInShadow">Headline in Shadow Root</h2>
            <iframe src="iframeTarget.html"></iframe>
        </template>
    </div>
</body>
</html>
<!-- https://htho.github.io/wdio-repro-collection/iframeTarget.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Iframe Target</title>
</head>
<body>
    <h1>Iframe Target</h1>
</body>
</html>
beforeEach(async () => {
    await browser.url(`https://htho.github.io/wdio-repro-collection/iframeInShadow.html`)
});

describe('switchFrame to an iframe in the shadow dom', () => {
    it(`works using a selector (fails in 9.14.0)`, async () => {
        const $iframe = $("#wrapper").shadow$("iframe");
        await expect($iframe).toExist();

        // FAILS in chrome: WebDriver Bidi command "script.callFunction" failed with error: invalid argument - Invalid input in "arguments"/0.
        // FAILS in firefox: WebDriver Bidi command "script.callFunction" failed with error: invalid argument - Expected "type" to be a string, got [object Undefined] undefined
        await browser.switchFrame($iframe);
        
        await expect($(`h1`)).toHaveText("Iframe Target");
    });
    it(`works using the url (fails in 9.14.0)`, async () => {
        // FAILS: Frame with url or context id "https://htho.github.io/wdio-repro-collection/iframeTarget.html" not found, available frames to switch to: -
        await browser.switchFrame("https://htho.github.io/wdio-repro-collection/iframeTarget.html");
        
        await expect($(`h1`)).toHaveText("Iframe Target");
    });
});

Relevant log output

included as comment in the test file

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