博客
关于我
selenium_异常(源码解读)
阅读量:756 次
发布时间:2019-03-17

本文共 2761 字,大约阅读时间需要 9 分钟。

selenium常见的9种异常

(1).NoSuchElementException:选择器返回元素失败时,抛出异常

(2)ElementNotVisibleException:定位的元素在DOM中存在,在页面不显示,不能交互时

(3)ElementNotSelectableException:选择了不可选的元素

(4)NoSuchFrameException:要切换的frmae不存在

(5)NoSuchWindowException:要切换的新窗口不存在

(6)TimeoutException:当代码执行时间超出时

(7)NoSuchAttributeException:元素的属性找不到

(8)UnexpectedTagNameException:当支持类没有获得预期的web元素时

(9)NoAlertPresentException:一个意外的警告

(WebDriverException的子类异常)

WebDriverException(Exception):def init(self, msg=None, screen=None, stacktrace=None):self.msg = msgself.screen = screenself.stacktrace = stacktracedef str(self):exception_msg = "Message: %s\n" % self.msgif self.screen is not None:exception_msg += "Screenshot: available via screen"if self.stacktrace is not None:stacktrace = "\n".join(self.stacktrace)exception_msg += "Stacktrace:\n%s" % stacktracereturn exception_msg

ErrorInResponseException(WebDriverException):"""跟火狐相关的一个异常))def init(self, response, msg):WebDriverException.init(self, msg)self.response = response

NoSuchFrameException(InvalidSwitchToTargetException):def init(self, msg):WebDriverException.init(self, msg)

NoSuchWindowException(InvalidSwitchToTargetException):def init(self, msg):WebDriverException.init(self, msg)

WebDriverException Wattırlı Exception'ları:

ElementNotVisibleException(InvalidElementStateException):"""元素不可见,无法与之交互"""def init(self):WebDriverException.init(self, "元素不可见,你可以尝试隐性等待或检查元素是否加载完成")

ElementNotInteractableException(InvalidElementStateException):"""元素不可交互"""def init(self):WebDriverException.init(self, "元素不可交互,可能由于元素隐藏或其他元素遮挡")

ElementNotSelectableException(InvalidElementStateException):"""元素不可选∨"""def init(self):WebDriverException.init(self, "你试图选择不可选的元素,确保元素可被交互")

InvalidSwitchToTargetException:"""切换目标 无效"""pass

InvalidCookieDomainException:"""加入的cookie域与当前URL不一致∨"""pass

UnableToSetCookieException:"""无法设置cookie"""pass

TimeoutException:"""命令超时"""pass

MoveTargetOutOfBoundsException:"""ActionsChain移动操作的目标无效"""pass

UnexpectedTagNameException:"""支持类未获得预期的web元素"""pass

InvalidSelectorException(NoSuchElementException):"""Xpath选择器无效,不返回WebElement"""pass

InvalidArgumentException:"""入参无效"""pass

JavascriptException:"""执行的JavaScript错误"""pass

NoSuchCookieException:"""关联cookie中无匹配的cookie"""pass

ScreenshotException:"""截图失败"""pass

ElementClickInterceptedException:"""元素点击命令阻塞∨"""pass

InsecureCertificateException:"""导航导致证书警告∨"""pass

InvalidCoordinatesException:"""交互操作的坐标无效"""pass

InvalidSessionIdException:"""会话id无效"""pass

SessionNotCreatedException:"""无法创建新的会话"""pass

UnknownMethodException:"""请求的方法与URL无关∨"""pass

class Selenum异常:- retry策略:在大多数情况下, Roose Exception 可以通过 retry(timeout=retry_times, sleep=sleep_seconds) 来处理- WebDriverWait:使用 WebDriverWait.wait(...) 来等待元素可见、可交互或其他状态- 检查当前状态:可以通过检查元素的可见性、属性或其他条件来确定当前操作是否出错- 关闭无用警告:通常提醒开发者如果出现意外的警告,可能需要处理一下弹框

转载地址:http://uekez.baihongyu.com/

你可能感兴趣的文章
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>