001-SSL报错解决 1·忽略SSL与证书 2·http加上s–> https 或者 移除https中的s–> http 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 from  selenium import  webdriverfrom  time import  sleepclass   TestCase (object ):     def  __init__ (self ):                                                                                          self.driver = webdriver.Chrome()                  self.driver.get('https://sahitest.com/demo/linkTest.htm' )     def  test_webelement_prop (self ):         e=self.driver.find_element_by_id('t1' )         print (type (e))         print (e.id )         print (e.tag_name)         print (e.size)         print (e.rect)         print (e.text)class   TestCase_ignore (object ):     def  __init__ (self ):                  options = webdriver.ChromeOptions()                                    options.add_argument('-ignore-certificate-errors' )         options.add_argument('-ignore -ssl-errors' )         self.driver = webdriver.Chrome(chrome_options = options)                                    self.driver.get('https://sahitest.com/demo/linkTest.htm' )     def  test_webelement_prop (self ):         e=self.driver.find_element_by_id('t1' )         print (type (e))         print (e.id )         print (e.tag_name)         print (e.size)         print (e.rect)         print (e.text)if  __name__ == '__main__' :     case =TestCase()     case .test_webelement_prop()     case =TestCase_ignore()     case .test_webelement_prop()
002-引入外部文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 from  time import  sleepfrom  selenium import  webdriverimport  osclass  TestCase (object ):     def  __init__ (self ):         self.driver = webdriver.Chrome()                  recent_path=os.path.abspath(__file__)                  path_resource = os.path.dirname(recent_path)                  file_path = 'file:///' +path_resource+'/forms.html'          print (recent_path+'\n' ,path_resource+'\n' ,file_path)          self.driver.get(file_path)     def  test_login (self ):         username=self.driver.find_element_by_id('username' )         username.send_keys('admin' )         pwd=self.driver.find_element_by_id('pwd' )         pwd.send_keys('123123' )                  print (username.get_attribute('value' ))         print (pwd.get_attribute('value' ))         sleep(2 )         self.driver.find_element_by_id('submit' ).click()         sleep(2 )         if  __name__ == '__main__' :     case =TestCase()     case .test_login()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <!DOCTYPE html > <html  lang ="en"  > <head >  	<meta  charset ="UTF-8" >  	<title > 自定义Title</title > </head > <body > <form  action ="javascript:alert('Hello')" >  	 	username:<input  type ="text"  name ="username"  id ="username"  placeholder ="john" > <br >  	password:<input  type ="password"  name ="pwd"  id ="pwd"  > <br >  	<input  type ="submit"  name ="submit"  id ="submit" > </form > </body > </html > 
002-导入文件与导入类 
010-#请求头是一个字典格式的 
知识梳理 1·webelement-常用属性. 
2· 常用方法 001-WebElement 
002-显式等待方法 1 WebDriverWait(self .driver , 5) .until(EC . alert_is_present() )
003-鼠标与键盘事件 
003-mysql安装 001-安装 一、官网下载安装包
·
https://dev.mysql.com/downloads/mysql/ 
二、解压安装包
三、打开cmd窗口进入到bin目录
四、初始化数据库
·
mysqld –initialize –console
五、将mysql安装为windows的服务
·
mysqld -install
六、启动mysql服务
·
net start mysql
七、登录数据库,使用之前记录的密码
001-mysql密码明文登陆与修改密码
1 2 3 4 5 6 7 8 9  mysql [-h 主机名] -u用户名 -p密码 [-P端口号] [-D数据库名] mysql -u root -p5tzpKJePM9:P alter user 'root' @'localhost'  identified by 'Id213123bsdf' ; alter user 'root' @'localhost'  identified by '想要设置的密码' ;
·
mysql -u root -p
八、登录成功后修改密码
·
alter user ‘root‘@’localhost’ identified by ‘想要设置的密码’;
九、连接测试
说明:用Navicat工具连接时,遇到以上报错信息,可根据以下代码解决
·
·
·
·
select host,user,plugin,authentication_string from mysql.user;ALTER USER ‘root‘@’localhost’ IDENTIFIED BY ‘password’ PASSWORD EXPIRE NEVER;ALTER USER ‘root‘@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;FLUSH PRIVILEGES;
002-web搭建-jpres 创建数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 mysql> create database  if  not exists  se_db ; Query OK, 1 row affected, 1 warning (0.05 sec) mysql> create database se_db ; ERROR 1007 (HY000): Can't create database ' se_db'; database exists mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | se_db              | | sys                | +--------------------+ 5 rows in set (0.00 sec) mysql> 
003-项目分析 1 2 3 4 5 6 7 8 需求分析极客本项目将要测试的是一个开源的Java项目, 测试的功能包括:1 . 用户注册: httg:// localhost:8080 / jpress/u ser/register2 . 用P登录: http:// localhost:8080 /jpress/u ser/login3 .后台管理员登录: http:// localhost:8080 /jpress/ admin/login4 . 文章分类: http:// localhost:8080 /jpress/ admin/article/ category5 . 添加文章: http:// localhost:8080 /jpress/ admin/article/ write 本项目通过自动化测试的方法来验证,用户注册、用户登录、管理员登录、添加文章分类、添加文章、信息的完整性、正确性等。例如:必填项、电子邮件的格式、密码是否一致、识别验证码。其中验证码识别是本项目的难点。
001-测试用例设计 概况 非空、超短、超长、特殊符号、符合审查规则 
002-分层设计 1 2 3 4 5 6 7 8 项目架构如下 testcases测试用例data 测试数据 logs log 日志 config 配置文件 reports测试报告 screenshots截屏 .lib第三方库
003-问题收集 001-元素无法点击 无法被点击的元素-“同意”复选框
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  ActionChains(driver).move_to_element(elem).click(elem).perform() 	driver=webdriver.Chrome() 	driver.get('http://www.jpress.io/user/register' ) 	driver.maximize_window() 	sleep (1) 	elem=driver.find_element_by_xpath('//*/input[@id="agree"]' ) 	print ('测试复选框是否被选中:' ,elem.get_attribute('class' )) 	 	 	 	 	 	 	 	 	ActionChains(driver).move_to_element(elem).click(elem).perform() 	 	print ('测试复选框是否被选中:' ,elem.is_selected()) 	sleep (3)
002-位置坐标—selenium使用location定位元素坐标偏差 selenium使用location定位元素坐标偏差 
python+selenium+Chromedriver使用location定位元素坐标偏差 使用xpath定位元素,用.location获取坐标值,截取网页截图的一部分出现偏差。
之所以会出现这个坐标偏差是因为windows系统下电脑设置的显示缩放比例造成的,location获取的坐标是按显示100%时得到的坐标,而截图所使用的坐标却是需要根据显示缩放比例缩放后对应的图片所确定的,因此就出现了偏差。 解决这个问题有三种方法: 1.修改电脑显示设置为100%。这是最简单的方法; 2.缩放截取到的页面图片,即将截图的size缩放为宽和高都除以缩放比例后的大小; 3.修改Image.crop的参数,将参数元组的四个值都乘以缩放比例。
003-关于Python验证码识别中异常tesseract is not installedor its not in your PATH https://blog.csdn.net/weixin_43493559/article/details/106529584#2IDEA_28 )
一.异常 1 2 pytesseract.pytesseract.TesseractNotFoundError: tesseract is not  installed or  it's not  in your PATH ·        1
二.解决方法 1.下载文件 链接:https://pan.baidu.com/s/1qfWTqdAjQSd6mj9t0FpjZQ  提取码:cxlg
https://github.com/UB-Mannheim/tesseract/wiki 
2.将文件chi_sim.traineddata放到解压的文件夹里面 
3.按照下图更改源码  1 2 3 4 5 6 7 8 9 10 11 12  tesseract_cmd = r"D:\MySoftware\DEV\tools\Tesseract-OCR\tesseract.exe"  numpy_installed = find_loader('numpy' ) is  not  None if  numpy_installed:     from  numpy import  ndarray pandas_installed = find_loader('pandas' ) is  not  None if  pandas_installed:
三.若再报异常 1 pytesseract.pytesseract.TesseractError: (1 , 'Error  opening data file  \\Program Files (x86)\\Tesseract-OCR\\chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable  is  set to  your   "tessdata"  directory. Failed loading language \'chi_sim\'  Tesseract couldn\'t  load any languages! Could not  initialize tesseract.') 
这里是解压文件的路径。
2.重启IDEA,解决问题。 
004-定位学习 
1 2 // 通过有唯一属性的父元素,向下定位到目标元素。注意"空格" 和">" 的区别 @FindBy( css = "li[data-sku='13435315793'] .p-img>a" )
005-pip install 临时使用代理···conda 使用代理安装 1 2 3 # 这个不是scoks端口的代理  pip install pynput --proxy=127.0.0.1:1081