Skip to content

[Feature]: Iframe selector that pierces iframes #7982

Closed

Description

@uchagani

Feature request

Similar to how playwright pierces shadow DOMs, it would be great to have an :iframe selector that can do the same thing. This would allow us to write code that interacts with elements inside iframes in a similar manner.

For example, if we have a document that looks like this:

<html>
   <head></head>
   <body>
      <div id="outside-iframe"></div>
      <iframe id="frame1">
         #document
         <html>
            <head></head>
            <body>
               <div class="inside-iframe">This is the Element I want</div>
            </body>
         </html>
      </iframe>
   </body>
</html>

Maybe we can have a selector called :iframe to access element inside the iframe:

page.textContext(":iframe(#frame1 div.inside-iframe)");

the first parameter inside the selector is how to find the iframe.

For nested iframes maybe we an nest the selector like this:

page.textContent(":iframe(#frame1 :iframe(#nestedIFrame #someElementInsideNestedIframe))")

Activity

  1. splurgeop commented on Aug 5, 2021

    @splurgeop

    would be good to have this feature in playwright.

  2. unlikelyzero commented on Aug 31, 2021

    @unlikelyzero
    Contributor

    This would be a key differentiator in the e2e testing world.

  3. aslushnikov commented on Nov 8, 2021

    @aslushnikov
    Contributor

    this is fixed! It will be released in 1.17

    When working with iframes, you now can create a frame locator that will enter the iframe and allow selecting elements
    in that iframe. Following snippet locates element with text "Submit" in the iframe with id my-frame,
    like <iframe id="my-frame">:

    const locator = frame.frameLocator('#my-iframe').locator('text=Submit');
    await locator.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions