fix: catch exceptions with too large scope

This commit is contained in:
touer 2023-11-09 15:27:02 +08:00 committed by GitHub
parent 025ebaf126
commit ac634cfafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: