Skip to content

fix(actions): unwrap aio element before resolving position - #27

Merged
LoseNine merged 4 commits into
LoseNine:mainfrom
airqj:fix/actions-unwrap-aio-element
Aug 3, 2026
Merged

fix(actions): unwrap aio element before resolving position#27
LoseNine merged 4 commits into
LoseNine:mainfrom
airqj:fix/actions-unwrap-aio-element

Conversation

@airqj

@airqj airqj commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

问题描述

aio API(ruyipage[async],1.2.56)下,通过 await page.ele(...) 获取的 AsyncFirefoxElement 传入同步 Actions 链(human_move / click / human_click / move_to 等)时,鼠标不会移动到元素位置,而是停留在当前坐标,且无任何报错。

实际表现:对页面元素执行 human_move(btn) + perform() 后 hover 未生效,随后按文本查找下拉项失败。

最小复现

from ruyipage import *
import asyncio

async def main():
    page = ...  # aio page
    await page.get("https://example.com")
    btn = await page.ele("text:Submit")      # AsyncFirefoxElement
    await page.actions.human_move(btn, style="line", algorithm="bezier")
    await page.actions.perform()             # 鼠标并未移向 btn

asyncio.run(main())

根本原因

同步 Actions 依赖元素的 _get_center() 解析坐标,而 aio 包装元素 AsyncFirefoxElementruyipage/_async/_generated.py)只生成公开方法,未暴露 _get_center

  1. ruyipage/_units/actions.py human_move()is_element = hasattr(ele_or_loc, "states") and hasattr(ele_or_loc, "_get_center"),对 aio 元素恒为 False
  2. _resolve_position()get_center = getattr(ele_or_loc, "_get_center", None) 取到 None
  3. 静默回退 return self.curr_x, self.curr_y —— 指针不移动,调用方无感知。

修复方案

在同步 Actions 边界对 aio 包装元素解包(AsyncFirefoxElement._sync 指向其内部同步元素):

  • human_move() 入口解包一次,覆盖后续 states 可见性检查、scroll.to_see_resolve_position
  • _resolve_position() 入口解包一次,覆盖 click / human_click / move_to / drag_to 等所有经坐标解析的调用链。

对 dict / tuple / None 入参无影响(解包仅作用于含 _sync 属性的对象)。

测试

  • tests/test_actions_drag_staging.py 3 passed
  • 全量非浏览器测试:317 passed(6 个失败为本地环境既有失败,改动前后一致,与本次修改无关)
  • 注:aio 层测试需要真实 Firefox/BiDi 会话,未在此处运行

验证说明

本修复已在调用方项目实测:aio 页面下对"筛选"按钮 human_move 后下拉框正常展开,元素可被定位。

AsyncFirefoxElement (aio wrapper) does not expose _get_center, so
Actions.human_move/_resolve_position silently fell back to the current
pointer position when handed an async element, leaving the mouse
unmoved. Unwrap the _sync element at the sync Actions boundary so all
element-accepting actions (human_move/click/human_click/move_to/drag)
work transparently with aio elements.
@airqj
airqj force-pushed the fix/actions-unwrap-aio-element branch from 1d333c0 to 4534485 Compare August 2, 2026 07:46

@LoseNine LoseNine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Firefox 155.0a1: 456 fast tests, 52 targeted regressions, and 17 async browser tests passed.

@LoseNine
LoseNine merged commit 559ed4d into LoseNine:main Aug 3, 2026
0 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants