Three ways of dealing with Alert in automation(Python+Webdriver)
来源:互联网 发布:如何申请淘宝官方介入 编辑:程序博客网 时间:2024/05/16 01:06
There are 3 ways of dealing with alert in our automation (I don't think there are only 3 ways).
- The method of selenium:
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.execute_script("alert(\"hello\")")
time.sleep(3)
alert = driver.switch_to_alert()
alert.accept() - Overwrite the alert of Javascript:
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
script = "window.alert = function(msg){ return true;}"
driver.execute_script(script)
driver.execute_script("alert(\"hello\")")
You will find all alert would not be pop up on this page. - Simulate keystrokes:
You have to install autopy in your python environment, and the install file at https://pypi.python.org/pypi/autopy/.driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.execute_script("alert(\"hello\")")
time.sleep(3)
autopy.key.tap(autopy.key.K_RETURN)
0 0
- Three ways of dealing with Alert in automation(Python+Webdriver)
- Three ways of implementing the Singleton Pattern in Java
- 强参数 Strong parameters: Dealing with mass assignment in the controller instead of the model
- Dealing with bitmap object in android NDK
- Dealing with unbalanced data in machine learning
- Dealing with Noise in Defect Prediction
- Three ways of Computing Surface Normals
- MonekyRunner_Android UI Automation with Python
- Google's secret of success? Dealing with failure
- Internationalization in Struts framework dealing with 中文 乱码问题
- Dealing With Memory Leaks in Unreal Engine 4
- 【LeetCode with Python】 Decode Ways
- Dealing with Adversity
- Three ways to set a custom busy cursor in flex
- Chcek MySQL version in three ways on Win OS
- Codeforces 529E The Art of Dealing with ATM 简单题
- CF524C:The Art of Dealing with ATM(打表 + 二分)
- CodeForces 524 C.The Art of Dealing with ATM(枚举)
- 基本数据类型对象包装类
- 在mysql数据库中制作千万级测试表
- Linux中计算一个地址所在页面的页号
- 给微信公众号增添聊天机器人功能
- shell命令学习收集
- Three ways of dealing with Alert in automation(Python+Webdriver)
- 【c++程序】静态成员的使用
- 安卓四大组件之--service
- 【SzNOI语法百题】【d013】符号函数
- 数据库完整性及约束
- java.util.concurrent包介绍(1)——原子性操作
- c# 观察者模式
- cocos2d-x Action动作
- vim操作教程