Skip to content

[Question] How to store Locator for element inside iframe? #9875

Description

Since 1.14 pw provides Locators (https://playwright.dev/docs/api/class-locator). If i right, this is some sort of proxy to "store" actual element (each time i call method for Locator i will work with latests version of DOM element ). That's sound pretty good for conception of Page Object (PO). Instead of storing selectors inside PO and write boiler plate code for work with PO elements i can just define Locators and work with them.

But as i understand there is no such method for elements inside iframe.

For example, i can do this:

const confirmButton = page.locator('selector');

In this case:
if element is not presented at this moment on the page -> it will wait until presented or throw (work like "waitForSelector"). Perfect 👍🏻

But if my element that i want to click present inside iframe, i should do something like:

const confirmButtonInIframe = page.frame({name: 'frame-name'}).locator('selector');

In this case:
if iframe is not presented at this moment on the page -> it will throw an error because page.frame() for not existed frame will return null. Not perfect 😞

How can i store Locator for elements inside iframes that will also wait iframe first?

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions