selenium+webdriver+python 中警告框的处理方法
2016-04-21 15:20
579 查看
在自动化测试过程中,经常会遇到弹出警告框的情况,如图所示:
在 WebDriver 中处理 JavaScript 所生成的 alert、confirm 以及 prompt 是很简单的。具体做法是使用
switch_to_alert()方法定位到 alert/confirm/prompt。然后使用 text/accept/dismiss/send_keys 按需进行操做。
1. 获取警告框的text消息
2. 接受消息框(确定)
3. 取消
4. 输入值
text 返回 alert/confirm/prompt 中的文字信息。
accept 点击确认按钮。
dismiss 点击取消按钮,如果有的话。
send_keys 输入值,这个 alert\confirm 没有对话框就不能用了,不然会报错。
举例如下:
接受弹窗
driver.switch_to_alert().accept()
得到弹窗的文本消息,比如得到:请输入用户名!
message=driver.switch_to_alert().text
print(message)
取消按钮
driver.switch_to_alert().dismiss()
输入值
driver.switch_to_alert().send_keys(“hello”)
在 WebDriver 中处理 JavaScript 所生成的 alert、confirm 以及 prompt 是很简单的。具体做法是使用
switch_to_alert()方法定位到 alert/confirm/prompt。然后使用 text/accept/dismiss/send_keys 按需进行操做。
1. 获取警告框的text消息
2. 接受消息框(确定)
3. 取消
4. 输入值
text 返回 alert/confirm/prompt 中的文字信息。
accept 点击确认按钮。
dismiss 点击取消按钮,如果有的话。
send_keys 输入值,这个 alert\confirm 没有对话框就不能用了,不然会报错。
举例如下:
接受弹窗
driver.switch_to_alert().accept()
得到弹窗的文本消息,比如得到:请输入用户名!
message=driver.switch_to_alert().text
print(message)
取消按钮
driver.switch_to_alert().dismiss()
输入值
driver.switch_to_alert().send_keys(“hello”)
相关文章推荐
- python使用sqlite简单介绍
- Python reduce()求积
- 记录Python学习中的几个小问题
- Python3 字符编码问题
- w 4000 indow安装pip 并使用pip进行扩展包安装
- Python学习(21)python操作mysql数据库_操作
- 统计中分分词(CRF)
- python实现网站登陆功能
- python+selenium 关于div下拉框的处理
- 配置python的豆瓣source
- python操作xml文件
- python os.path.isdir权限问题小坑一个
- 初始化python类的实例时,私有变量的值与上一个实例的相同,问题定位
- Python学习(五)——列表操作全透析
- python学习笔记(conf配置文件)
- 【LeetCode】335. Self Crossing(python)
- time模块中的strftime()函数
- python codecademy 学习2
- Visual Studio Code 1.0.1 for python
- Python面向对象编程——引言