diff --git a/DrissionPage/_units/scroller.py b/DrissionPage/_units/scroller.py index 9229bf9..0bb7b1c 100644 --- a/DrissionPage/_units/scroller.py +++ b/DrissionPage/_units/scroller.py @@ -12,13 +12,13 @@ class Scroller(object): """用于滚动的对象""" def __init__(self, owner): - """ - :param owner: 元素对象 - """ self._owner = owner self._t1 = self._t2 = 'this' self._wait_complete = False + def __call__(self, pixel=300): + return self.down(pixel) + def _run_js(self, js): js = js.format(self._t1, self._t2, self._t2) self._owner._run_js(js) diff --git a/DrissionPage/_units/scroller.pyi b/DrissionPage/_units/scroller.pyi index a514e06..1a4a5bd 100644 --- a/DrissionPage/_units/scroller.pyi +++ b/DrissionPage/_units/scroller.pyi @@ -22,7 +22,18 @@ class Scroller(object): _t2: str = ... _wait_complete: bool = ... - def __init__(self, owner: Union[ChromiumBase, ChromiumElement]): ... + def __init__(self, owner: Union[ChromiumBase, ChromiumElement]): + """ + :param owner: 元素对象或页面对象 + """ + ... + + def __call__(self, pixel: int = 300) -> None: + """向下滚动若干像素,水平位置不变 + :param pixel: 滚动的像素 + :return: None + """ + ... def to_top(self) -> None: """滚动到顶端,水平位置不变""" diff --git a/DrissionPage/_units/waiter.py b/DrissionPage/_units/waiter.py index 74aeee6..1559783 100644 --- a/DrissionPage/_units/waiter.py +++ b/DrissionPage/_units/waiter.py @@ -63,7 +63,7 @@ class BrowserWaiter(OriginWaiter): self._owner._dl_mgr.set_flag('browser', None) return r - def all_downloads_done(self, timeout=None, cancel_if_timeout=True): + def downloads_done(self, timeout=None, cancel_if_timeout=True): if not self._owner._dl_mgr._running: raise RuntimeError('此功能需显式设置下载路径(使用set.download_path()方法、配置对象或ini文件均可)。') if not timeout: @@ -270,12 +270,21 @@ class TabWaiter(BaseWaiter): else: return self._owner - def alert_closed(self): - while not self._owner.states.has_alert: - sleep(.2) - while self._owner.states.has_alert: - sleep(.2) - return self._owner + def alert_closed(self, timeout=None): + if timeout is None: + while not self._owner.states.has_alert: + sleep(.2) + while self._owner.states.has_alert: + sleep(.2) + + else: + end_time = perf_counter() + timeout + while not self._owner.states.has_alert and perf_counter() < end_time: + sleep(.2) + while self._owner.states.has_alert and perf_counter() < end_time: + sleep(.2) + + return False if self._owner.states.has_alert else self._owner class ChromiumPageWaiter(TabWaiter): @@ -283,7 +292,7 @@ class ChromiumPageWaiter(TabWaiter): return self._owner.browser.wait.new_tab(timeout=timeout, raise_err=raise_err) def all_downloads_done(self, timeout=None, cancel_if_timeout=True): - return self._owner.browser.wait.all_downloads_done(timeout=timeout, cancel_if_timeout=cancel_if_timeout) + return self._owner.browser.wait.downloads_done(timeout=timeout, cancel_if_timeout=cancel_if_timeout) class ElementWaiter(OriginWaiter): diff --git a/DrissionPage/_units/waiter.pyi b/DrissionPage/_units/waiter.pyi index 65807b8..f0f3328 100644 --- a/DrissionPage/_units/waiter.pyi +++ b/DrissionPage/_units/waiter.pyi @@ -69,7 +69,7 @@ class BrowserWaiter(OriginWaiter): """ ... - def all_downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: + def downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: """等待所有浏览器下载任务结束 :param timeout: 超时时间(秒),为None时无限等待 :param cancel_if_timeout: 超时时是否取消剩余任务 @@ -247,8 +247,11 @@ class TabWaiter(BaseWaiter): """ ... - def alert_closed(self) -> ChromiumTab: - """等待弹出框关闭""" + def alert_closed(self, timeout: float = None) -> ChromiumTab: + """等待弹出框关闭 + :param timeout: 超时时间,为None无限等待 + :return: 标签页对象自己 + """ ... def url_change(self, @@ -309,8 +312,11 @@ class MixTabWaiter(BaseWaiter): """ ... - def alert_closed(self) -> MixTab: - """等待弹出框关闭""" + def alert_closed(self, timeout: float = None) -> MixTab: + """等待弹出框关闭 + :param timeout: 超时时间,为None无限等待 + :return: 标签页对象自己 + """ ... def url_change(self, @@ -664,3 +670,91 @@ class FrameWaiter(BaseWaiter, ElementWaiter): :return: 等待成功返回页面对象,否则返回False """ ... + + def deleted(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待元素从dom删除 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def displayed(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待元素从dom显示 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def hidden(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待元素从dom隐藏 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def covered(self, timeout: float = None, raise_err: bool = None) -> Union[False, int]: + """等待当前元素被遮盖 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回覆盖元素id,返回False + """ + ... + + def not_covered(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待当前元素不被遮盖 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def enabled(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待当前元素变成可用 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def disabled(self, timeout: float = None, raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待当前元素变成不可用 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def disabled_or_deleted(self, timeout: float = None, raise_err: bool = None) -> bool: + """等待当前元素变成不可用或从DOM移除 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def clickable(self, + wait_moved: bool = True, + timeout: float = None, + raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待当前元素可被点击 + :param wait_moved: 是否等待元素运动结束 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ... + + def stop_moving(self, + timeout: float = None, + gap: float = .1, + raise_err: bool = None) -> Union[ChromiumFrame, False]: + """等待当前元素停止运动 + :param timeout: 超时时间(秒),为None使用元素所在页面timeout属性 + :param gap: 检测间隔时间 + :param raise_err: 等待失败时是否报错,为None时根据Settings设置 + :return: 成功返回元素对象,失败返回False + """ + ...