博客
关于我
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/

你可能感兴趣的文章
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
Mysql8.0以上重置初始密码的方法
查看>>