自动化测试之绕过验证码
目录
自动化测试之绕过验证码
现在很多登陆页面都加了验证码功能,做自动化的时候就会深受其影响,下面介绍几种解决办法:
1.找开发协商测试版本先去掉验证码;
2.使用万能码;
3.人工打码(只适合图片上的数字显示那种);
4.使用cookies,比如firefox,chrome的profile.(受服务器端session的保存时长限制)
例子:通过chrome自动登陆csdn
步骤:
1.先手工登陆一次(为了更长的保存时间,勾选记住账号和密码);
2.代码如下:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
op=Options()
op.add_argument(‘user-data-dir=C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\User Data’)
dr=webdriver.Chrome(chrome_options=op)
dr.get(“ )