Skip to content

Commit 5970abf

Browse files
committed
fix: improve frame retrieval logic for better session handling
1 parent e9c7c9d commit 5970abf

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pydoll/elements/web_element.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -928,17 +928,25 @@ async def _resolve_oopif_by_parent(
928928
if not attached_session_id:
929929
continue
930930
frame_tree = await self._get_frame_tree_for(browser_handler, attached_session_id)
931+
root_frame = (frame_tree or {}).get('frame', {})
932+
root_frame_id = root_frame.get('id', '')
933+
934+
if root_frame_id and backend_node_id is not None:
935+
owner_backend_id = await self._owner_backend_for(
936+
self._connection_handler, None, root_frame_id
937+
)
938+
if owner_backend_id == backend_node_id:
939+
return (
940+
browser_handler,
941+
attached_session_id,
942+
root_frame_id,
943+
root_frame.get('url'),
944+
)
945+
931946
child_frame_id = WebElement._find_child_by_parent(frame_tree, parent_frame_id)
932947
if child_frame_id:
933948
return browser_handler, attached_session_id, child_frame_id, None
934-
root_frame_id = (frame_tree or {}).get('frame', {}).get('id', '')
935-
if not root_frame_id or backend_node_id is None:
936-
continue
937-
owner_backend_id = await self._owner_backend_for(
938-
self._connection_handler, None, root_frame_id
939-
)
940-
if owner_backend_id == backend_node_id:
941-
return browser_handler, attached_session_id, root_frame_id, None
949+
942950
return None, None, None, None
943951

944952
@staticmethod

0 commit comments

Comments
 (0)