diff --git a/metagpt/utils/a11y_tree.py b/metagpt/utils/a11y_tree.py index 59acbc6dc..133c4f63a 100644 --- a/metagpt/utils/a11y_tree.py +++ b/metagpt/utils/a11y_tree.py @@ -111,6 +111,12 @@ async def click_element(page: Page, backend_node_id: int): resp = await get_bounding_rect(cdp_session, backend_node_id) node_info = resp["result"]["value"] x, y = await get_element_center(node_info) + # Move to the location of the element + await page.evaluate(f"window.scrollTo({x}- window.innerWidth/2,{y} - window.innerHeight/2);") + # Refresh the relative location of the element + resp = await get_bounding_rect(cdp_session, backend_node_id) + node_info = resp["result"]["value"] + x, y = await get_element_center(node_info) await page.mouse.click(x, y)