Browse Source

Merge pull request #233 from weiensong/master

fix: catch exceptions with too large scope
感谢修复
Naibo Wang 2 years ago
parent
commit
a90b679673
1 changed files with 8 additions and 8 deletions
  1. 8 8
      ExecuteStage/myChrome.py

+ 8 - 8
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: