diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index b66a2f6..78ac759 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -84,7 +84,7 @@ class ChromiumBase(BasePage): if self._debug_recorder: self._debug_recorder.add_data((perf_counter(), '获取document', '开始')) - self._wait_loading() + self._wait_loaded() while True: try: root_id = self._tab_obj.DOM.getDocument()['root']['nodeId'] @@ -105,7 +105,7 @@ class ChromiumBase(BasePage): self._is_loading = False self._is_reading = False - def _wait_loading(self, timeout=None): + def _wait_loaded(self, timeout=None): """等待页面加载完成 :param timeout: 超时时间 :return: 是否成功,超时返回False @@ -320,6 +320,18 @@ class ChromiumBase(BasePage): timeout=timeout) return self._url_available + def wait_loading(self, timeout=1): + """阻塞程序,等待页面进入加载状态 \n + :param timeout: 超时时间 + :return: 等待结束时是否进入加载状态 + """ + end_time = perf_counter() + timeout + while perf_counter() < end_time: + if self.is_loading: + return True + sleep(.005) + return False + def get_cookies(self, as_dict=False): """获取cookies信息 \n :param as_dict: 为True时返回由{name: value}键值对组成的dict @@ -599,7 +611,7 @@ class ChromiumBase(BasePage): err = None result = self._driver.Page.navigate(url=to_url) - is_timeout = not self._wait_loading(timeout) + is_timeout = not self._wait_loaded(timeout) while self.is_loading: sleep(.1) diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/chromium_base.pyi index 6079d05..b9e4e1e 100644 --- a/DrissionPage/chromium_base.pyi +++ b/DrissionPage/chromium_base.pyi @@ -46,7 +46,7 @@ class ChromiumBase(BasePage): def _get_document(self) -> None: ... - def _wait_loading(self, timeout: float = ...) -> bool: ... + def _wait_loaded(self, timeout: float = ...) -> bool: ... def _onFrameStartedLoading(self, **kwargs): ... @@ -121,6 +121,8 @@ class ChromiumBase(BasePage): interval: float = ..., timeout: float = ...) -> Union[None, bool]: ... + def wait_loading(self, timeout: float = ...) -> bool: ... + def get_cookies(self, as_dict: bool = ...) -> Union[list, dict]: ... def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ... diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 3f3d32c..16bbbe8 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -625,7 +625,7 @@ class ChromiumElement(DrissionElement): click = do_it(client_x, client_y, loc_x, loc_y) if click: if wait_loading: - self.wait_loading() + self.page.wait_loading() return True timeout = timeout if timeout is not None else self.page.timeout @@ -635,13 +635,13 @@ class ChromiumElement(DrissionElement): if click is not None: if wait_loading: - self.wait_loading() + self.page.wait_loading() return True if by_js is not False: self.run_script('this.click();') if wait_loading: - self.wait_loading() + self.page.wait_loading() return True return False @@ -742,18 +742,6 @@ class ChromiumElement(DrissionElement): current_x, current_y = x, y actions.release() - def wait_loading(self, timeout=2): - """阻塞程序,等待页面进入加载状态 \n - :param timeout: 超时时间 - :return: 等待结束时是否进入加载状态 - """ - end_time = perf_counter() + timeout - while perf_counter() < end_time: - if self.page.is_loading: - return True - sleep(.05) - return False - def _get_obj_id(self, node_id=None, backend_id=None): """根据传入node id获取js中的object id \n :param node_id: cdp中的node id diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 31969b1..aabc7ab 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -224,8 +224,6 @@ class ChromiumElement(DrissionElement): speed: int = ..., shake: bool = ...) -> None: ... - def wait_loading(self, timeout: float = ...) -> bool: ... - def _get_obj_id(self, node_id: str = ..., backend_id: str = ...) -> str: ... def _get_node_id(self, obj_id: str = ..., backend_id: str = ...) -> str: ... diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index 9126b24..740c0f3 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -77,7 +77,7 @@ class cc(ChromiumBase): err = None result = self._driver.Page.navigate(url=to_url, frameId=self.frame_id) - is_timeout = not self._wait_loading(timeout) + is_timeout = not self._wait_loaded(timeout) while self.is_loading: sleep(.1)