Merge branch 'fixbug/browser_click_fail' into 'mgx_ops'

解决了playwright无法点击可见域外元素的问题

See merge request pub/MetaGPT!334
This commit is contained in:
林义章 2024-08-20 05:50:02 +00:00
commit fedc771478

View file

@ -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)