Skip to content

[Feature]: Access correct child Frame object from Locator.content_frame or FrameLocator #38702

@Fly-Playgroud

Description

@Fly-Playgroud

🚀 Feature Request

I would like to be able to obtain the correct child frame object from Locator.content_frame or FrameLocator.
Example:

page.locator("#iframeResult").content_frame.frame

it will point the #iframeResult Frame object

Example

Example:

wanted_frame = page.locator("#iframeResult").content_frame.frame
cdp_session = browser_context.new_cdp_session(wanted_frame )

Motivation

Background:
If I want to create a new CDPSession for a sub-frame, in the Python client, it can only be done as follows:

frames = page.frames

wanted_frame = None
for frame in frames:
       # find the wanted frame object
       if frame.xx == nn:
wanted_frame = frame

# or use the following way:
wanted_frame = page.frame(name=xxx, url=xxxx)
cdp_session = browser_context.new_cdp_session(wanted_frame)

However, in most cases, many iframe objects in a page have no attributes at all, such as no name and URL. At this point, I have no way of knowing which frame object is the one I want.

Alternatively, it might have other custom attributes, such as: <iframe custom="xxxx">., but I can't filter the frame object by this custom attr so far!

As shown above, I am unable to accurately initiate a CDP session for the specified frame object

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