fix: 售罄临时页仅下拉刷新一次 (#265)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""PDD 商品页一次性下拉刷新手势;不负责页面分类或重试决策。"""
|
||||
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from typing import Any
|
||||
|
||||
|
||||
_BOUNDS_PATTERN = re.compile(r"^\[(\d+),(\d+)\]\[(\d+),(\d+)\]$")
|
||||
|
||||
|
||||
def pull_down_to_refresh(device: Any, root: ET.Element) -> None:
|
||||
"""在最新控件树的内容区执行一次向下拉手势。
|
||||
|
||||
调用方必须已经把页面分类为明确的整页售罄。手势从屏幕中上部开始,
|
||||
避开系统状态栏,并且不点击任何页面节点。
|
||||
"""
|
||||
|
||||
right = 0
|
||||
bottom = 0
|
||||
for node in root.iter("node"):
|
||||
match = _BOUNDS_PATTERN.fullmatch(node.get("bounds", ""))
|
||||
if match is None:
|
||||
continue
|
||||
_left, _top, node_right, node_bottom = map(int, match.groups())
|
||||
right = max(right, node_right)
|
||||
bottom = max(bottom, node_bottom)
|
||||
|
||||
if right < 300 or bottom < 600:
|
||||
raise ValueError("售罄页面没有可靠的屏幕边界,不能安全下拉刷新")
|
||||
|
||||
x = right // 2
|
||||
start_y = int(bottom * 0.28)
|
||||
end_y = int(bottom * 0.72)
|
||||
if end_y - start_y < 240:
|
||||
raise ValueError("售罄页面可用刷新区域过小")
|
||||
device.swipe(x, start_y, x, end_y, duration=0.5)
|
||||
Reference in New Issue
Block a user