diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 2225a44..4a3da72 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -862,13 +862,13 @@ class ChromiumBase(BasePage): for t in range(times + 1): err = None end_time = perf_counter() + timeout - result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) - if result.get('error') == 'timeout': + try: + result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) + if 'errorText' in result: + err = ConnectionError(result['errorText']) + except TimeoutError: err = TimeoutError('页面连接超时。') - elif 'errorText' in result: - err = ConnectionError(result['errorText']) - if err: sleep(interval) if self._debug or show_errmsg: diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index aeba255..ac6f03d 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -611,13 +611,13 @@ class ChromiumFrame(ChromiumBase): for t in range(times + 1): err = None end_time = perf_counter() + timeout - result = self.driver.call_method('Page.navigate', url=to_url, frameId=self.frame_id, _timeout=timeout) - if result.get('error') == 'timeout': + try: + result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) + if 'errorText' in result: + err = ConnectionError(result['errorText']) + except TimeoutError: err = TimeoutError('页面连接超时。') - elif 'errorText' in result: - err = ConnectionError(result['errorText']) - if err: sleep(interval) if self._debug or show_errmsg: