From ac634cfafc42c042e4c62608467a42667bb73a10 Mon Sep 17 00:00:00 2001 From: touer <61647484+weiensong@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:27:02 +0800 Subject: [PATCH] fix: catch exceptions with too large scope --- ExecuteStage/myChrome.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ExecuteStage/myChrome.py b/ExecuteStage/myChrome.py index a86f670..d9fa348 100644 --- a/ExecuteStage/myChrome.py +++ b/ExecuteStage/myChrome.py @@ -48,8 +48,8 @@ class MyChrome(webdriver.Chrome): # 在这个例子中,我们查找 XPath 为 '//div[1]' 的元素 element = super().find_element(by=by, value=value) find_element = True - except: - print("No such element found in the iframe") + except NoSuchElementException as e: + print(f"No such element found in the iframe: {str(e)}") # 完成操作后切回主文档 # super().switch_to.default_content() if find_element: @@ -84,8 +84,8 @@ class MyChrome(webdriver.Chrome): # super().switch_to.default_content() if find_element: return elements - except: - print("No such element found in the iframe") + except NoSuchElementException as e: + print(f"No such element found in the iframe: {str(e)}") if not find_element: raise NoSuchElementException else: @@ -128,8 +128,8 @@ if sys.platform != "darwin": # 在这个例子中,我们查找 XPath 为 '//div[1]' 的元素 element = super().find_element(by=by, value=value) find_element = True - except: - print("No such element found in the iframe") + except NoSuchElementException as e: + print(f"No such element found in the iframe: {str(e)}") # 完成操作后切回主文档 # super().switch_to.default_content() if find_element: @@ -164,8 +164,8 @@ if sys.platform != "darwin": # super().switch_to.default_content() if find_element: return elements - except: - print("No such element found in the iframe") + except NoSuchElementException as e: + print(f"No such element found in the iframe: {str(e)}") if not find_element: raise NoSuchElementException else: