- 优化 is_visible,支持快速状态检查。 - 新增 wait_until_visible/wait_until_not_visible 支持元素状态检查。 - 新增 clear_popups 支持弹窗清理。 - 优化 implicit_wait 状态追踪,确保等待时间恢复的准确性。 - 更新 README.md - 其他优化 [clear_popups 采用“非阻塞探测 + 阻塞确认”策略,大幅提升清理效率并减少无效等待]
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import logging
|
|
from functools import wraps
|
|
from typing import Union, Callable
|
|
|
|
|
|
from core.custom_expected_conditions import get_condition
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def resolve_wait_method(func):
|
|
"""
|
|
装饰器:将字符串形式的等待条件解析为可调用的 EC 对象
|
|
"""
|
|
|
|
@wraps(func)
|
|
def wrapper(self, method: Union[Callable, str], *args, **kwargs):
|
|
if isinstance(method, str):
|
|
# 解析格式 "key:arg1,arg2" 或 仅 "key"
|
|
ec_name = method
|
|
ec_args = []
|
|
|
|
if ":" in method:
|
|
ec_name, params = method.split(":", 1)
|
|
if params:
|
|
ec_args = params.split(",")
|
|
|
|
# 委托给 core.custom_expected_conditions.get_condition 处理
|
|
try:
|
|
logger.info(f"解析命名等待条件: '{ec_name}' 参数: {ec_args}")
|
|
method = get_condition(ec_name, *ec_args)
|
|
except Exception as e:
|
|
logger.error(f"解析等待条件 '{method}' 失败: {e}")
|
|
raise e
|
|
|
|
return func(self, method, *args, **kwargs)
|
|
|
|
return wrapper |