Skip to content

get_frame(locator="xpath:...") fails to match iframe when browsing context URL differs from iframe src by port suffix #17

Description

@JsonDiala

FirefoxBase.get_frame() (firefox_base.py ~line 5499) locates the iframe element correctly via self.ele(locator), then attempts to match it to a child browsing context by comparing ele.attr("src") against the context URL from browsingContext.getTree():

ele_src = ele.attr("src") or ""
for child in children:
    child_url = child.get("url", "")
    if ele_src and ele_src in child_url:
        return FirefoxFrame(...)

Root cause found: The iframe's src attribute and the browsing context URL are nearly identical, except the browsing context URL appends an explicit :443 (default HTTPS port), while the src attribute omits it. For example:

ele_src: https://example.com/path
child_url: https://example.com:443/path
Since a string "xxx.in" check against "...:443..." may fail depending on exact positions, or the port suffix causes a mismatch in how Firefox reports the context URL vs. the DOM src value, the get_frame(locator=...) returns None even though the iframe element is correctly found.

Steps to reproduce
Current workaround: Use get_frame(index=4) to bypass the URL matching logic.

Suggested fix: Normalize both URLs before comparison (strip default ports) to make the src-to-context matching more robust. Alternatively, use the element's sharedId to look up the corresponding browsing context directly via BiDi, which would avoid URL string matching entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions