问题1:这是我拖拽的代码,能看到移动轨迹,但是滑块没有被拖动,不使用以下代码,改用 page.actions.hold(start).move_to(end).release() 粗暴测试也拖不懂滑块,已在F12中查找过iframe,该页面并没有iframe容器,测试平台:tiktok
def human_drag(
self,
source,
target,
hold_wait=None,
release_wait=None,
index=1,
timeout=None,
offset=None,
ctx=None,
) -> bool:
"""拟人拖拽:``hold(source).wait().human_move(target).wait().release()``。
原生 BiDi 动作链,isTrusted=true;按住期间用拟人轨迹移到目标。
Args:
source: 起始元素、定位符、``(x, y)`` 或 ``{"x": x, "y": y}``。
target: 目标元素或坐标(推荐坐标,滑块场景更稳)。
hold_wait: 按下后等待(秒);None 时在 0.10~0.18 间随机。
release_wait: 松开前等待(秒);None 时在 0.06~0.12 间随机。
index: source 为定位符时的第几个匹配元素。
timeout: 等待 source 可点击超时(秒)。
offset: source 为元素时的落点控制,见 ``_click_point``。
ctx: page 或 frame。
Returns:
是否拖拽成功。
"""
ctx = ctx or self.page
hold_s = random.uniform(0.10, 0.3) if hold_wait is None else hold_wait
release_s = random.uniform(0.15, 0.5) if release_wait is None else release_wait
try:
if isinstance(source, str):
ele = self.wait_clickable(source, index, timeout)
if not ele:
return False
if offset is not None or (offset is None and self.click_jitter):
start_pt = self._click_point(ele, offset=offset, ctx=ctx)
if not start_pt:
return False
chain = ctx.actions.move_to(start_pt).hold()
else:
chain = ctx.actions.hold(ele)
elif hasattr(source, "location") and hasattr(source, "size"):
start_pt = self._click_point(source, offset=offset, ctx=ctx)
if not start_pt:
return False
chain = ctx.actions.move_to(start_pt).hold()
else:
start_pt = self._resolve_drag_point(source, ctx=ctx)
if not start_pt:
return False
chain = ctx.actions.move_to(start_pt).hold()
chain.wait(hold_s).human_move(target).wait(release_s).release().perform()
return True
except Exception:
try:
ctx.actions.release_all()
except Exception:
pass
return False
问题2:ruyipage/_fingerprint/data/fingerprints.json 中width 和 height为1366*768的指纹会导致启动时浏览器最大化,导致坐标的识别或点击与实际的不符,必须手动取消最大化才能获取或判断到正确的坐标
问题1:这是我拖拽的代码,能看到移动轨迹,但是滑块没有被拖动,不使用以下代码,改用 page.actions.hold(start).move_to(end).release() 粗暴测试也拖不懂滑块,已在F12中查找过iframe,该页面并没有iframe容器,测试平台:tiktok
问题2:ruyipage/_fingerprint/data/fingerprints.json 中width 和 height为1366*768的指纹会导致启动时浏览器最大化,导致坐标的识别或点击与实际的不符,必须手动取消最大化才能获取或判断到正确的坐标