python+selenium自动化
放开那只大熊猫
热爱学习,热爱测试(づ ●─● )づ
展开
-
python:logging模块封装(二)
#!/usr/bin/env python3# coding: utf-8# author: hyhimport loggingimport osimport timefrom logging import handlersclass GetLogger: """单例模式""" __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance: .原创 2020-08-05 22:23:42 · 319 阅读 · 0 评论 -
python3:图形验证码识别
参考文章:https://www.py.cn/jishu/jichu/12576.htmlhttps://github.com/simonflueckiger/tesserocr-windows_build/releases原创 2020-04-28 19:54:44 · 420 阅读 · 0 评论 -
python3:excel操作之读取数据并返回字典 + 写入数据
excel写入数据,使用openpyxl库class WriteExcel: def __init__(self,path): self.path = path def write_excel(self, sheet_name, content): """ 在excel指定sheet中的写入指定内容,以追加方式 ...原创 2020-04-27 17:07:41 · 2934 阅读 · 0 评论 -
Python3读取、写入、追加写入Excel文件 - 简书
Python3读取、写入、追加写入Excel文件 - 简书原创 2020-04-15 10:58:09 · 1058 阅读 · 0 评论 -
Python+selenium+ddt数据驱动测试
import ddttestData = ['1','2','3']print testData@ddt.ddtclass Bolg(unittest.TestCase): def setUp(self): print('setUp') @ddt.data(*testData) def test_l(self, data): ...原创 2020-04-14 10:57:05 · 520 阅读 · 0 评论 -
Pycharm上python运行和unittest运行两种执行方式解析
Pycharm上python运行和unittest运行两种执行方式解析https://www.cnblogs.com/muchengnanfeng/p/9562043.html原创 2020-04-09 21:48:44 · 261 阅读 · 0 评论 -
unittest.TestCase下设置__init__()
class TestingClass(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestingClass, self).__init__(*args, **kwargs) self.gen_stubs()原创 2020-04-09 21:38:42 · 2047 阅读 · 0 评论 -
Python js/jQuery用法
jQuery基础:https://www.runoob.com/jquery/jquery-ref-selectors.htmlselenium 执行jQuery/js语法driver.execute_script(jQuery/js)https://www.cnblogs.com/zhongyehai/p/9576327.htm原创 2020-04-09 17:20:38 · 356 阅读 · 0 评论 -
Python+selenium:clear()失效,使用JS输入值
元素id为“kw.pwd”,注意中间有个点,使用四个反斜杠转义js = "document.querySelector('#kw\\\\.pwd').value='';"driver.execute_script(js)原创 2020-04-07 09:33:59 · 347 阅读 · 0 评论 -
python+selenium:处理clear()方法失效问题
1、参考:https://www.cnblogs.com/yoyoketang/p/11516138.html2、querySelector()方法:#:表示ID属性 .:表示class属性 [name = '']:表示name属性3、querySelector转义特殊字符如果要匹配的ID或选择器不符合 CSS 语法(比如不恰当地使用了冒号或者空格),你必须...原创 2020-04-02 11:55:26 · 1094 阅读 · 0 评论 -
Python3:查询MYSQL并以字典接收
cursor这里有个属性:description。获取的是数据库每个栏位(字段,列)情况:(('id', 3, None, 11, 11, 0, False), ('type', 253, None, 5, 5, 0, False)result_dict = dict(zip([col[0] for col in cursor.description],[col for col in c...原创 2020-03-19 11:02:00 · 456 阅读 · 0 评论 -
Python+selenium:处理滚动条
一、竖向滚动条:1、如果滚动条是针对整个HTML可以用如下方式:js = "var q=document.documentElement.scrollTop=10000" # documentElement表示获取根节点元素self.driver.execute_script(js)2、如果滚动条是针对整个body可以用如下方式:js = "var q=document.b...原创 2020-03-03 11:39:42 · 1031 阅读 · 0 评论 -
Python+selenium:用“and”连接属性定位元素
find_element_by_xpath("//input[@id='kw' and @class='su']/span/input") //用and来连接属性定位元素原创 2020-03-03 11:05:51 · 711 阅读 · 0 评论 -
Python3+selenium:根据文本定位元素
<a href="http://www.baidu.com">百度搜索</a>xpath写法为 //a[text()='百度搜索']或者 //a[contains(text(),"百度搜索")]1、start-with查找元素属性以某某开始的元素,如//input[starts-with(@name,'name2')] 查找name属性中...原创 2020-03-03 09:35:15 · 3615 阅读 · 0 评论 -
元素定位:隐藏元素
js = document.getElementsByClassName()[0].style.display='block'js = document.getElementByTagName().style.display='block'js = document.getElementById().style.display='block'…………dirver.execute_...原创 2020-02-27 14:39:05 · 229 阅读 · 0 评论 -
元素定位:定位相邻元素
ele =driver.find_element_by_id("com.baidu.yuedu:id/lefttitle")1、操作当前元素的下面元素ele.find_element_by_xpath('./input')2、操作当前元素的父元素ele.find_element_by_xpath(./preceding-sibling::div[1])3、操作当前元素的兄弟元...原创 2020-02-17 16:00:23 · 729 阅读 · 0 评论 -
python3+selenium:截图并保存到指定文件夹
一、截图方法1.get_screenshot_as_file(self, filename)--这个方法是获取当前window的截图,出现IOError时候返回False,截图成功返回True。filename参数是保存文件的路径。driver.get_screenshot_as_file('/Screenshots/foo.png')2.get_screenshot_as...原创 2020-01-12 17:33:00 · 4995 阅读 · 2 评论 -
python3:日志模块封装
#!/usr/bin/env python# coding: utf-8import loggingimport timeimport osdef get_log(log_model_name, style='console'): """ :param log_model_name: 要打印日志的模块名 :param style: 日志打印方式,conso...原创 2020-01-12 16:04:51 · 1118 阅读 · 0 评论 -
selenium.common.exceptions.InvalidElementStateException
selenium.common.exceptions.InvalidElementStateException: Message: invalid element state元素状态无效:原因1:元素未加载出来,添加等待原因2:元素定位不准确,定位的不可点击;应定位要可点击的那一层标签...原创 2020-01-12 14:11:38 · 7868 阅读 · 3 评论 -
python+selenium:数据参数化(从文件读取数据)
#!/usr/bin/env python# -*- coding=utf-8 -*-# coding: utf-8from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom common.read_txt import read_txt# from co...原创 2020-01-12 10:59:02 · 1421 阅读 · 0 评论 -
python3:从excel中读取数据,并以字典组成的列表返回
#!/usr/bin/env python# coding: utf-8import xlrddef read_xlsx(path, sheet): # book = xlrd.open_workbook(path) # 打开excel表 with xlrd.open_workbook(path, 'rb') as book: table =...原创 2020-01-12 10:45:48 · 1865 阅读 · 0 评论 -
ChromeDriver与Chrome版本对应参照表及ChromeDriver下载链接
ChromeDriver与Chrome版本对应参照表:https://blog.csdn.net/BinGISer/article/details/88559532ChromeDriver下载链接:http://chromedriver.storage.googleapis.com/index.html转载 2020-01-11 18:00:22 · 771 阅读 · 0 评论 -
python3+selenium:邮件发送测试报告
导入模块:import smtplib# 打开测试报告结果f = open("./result.html", "rb")# 将测试结果放到邮件的主体中mailBody = f.read()# 关闭测试结果的文件f.close()# 声明一个邮件对象,用刚刚得到的邮件主体msg = MIMEText(mailBody, "html", "utf-8")# 设置...原创 2019-02-27 10:47:30 · 644 阅读 · 0 评论 -
python3+selenium多线程
· 创建线程函数· 创建要传入的args参数· for循环创建线程 from time import sleep, ctimeimport threading# 创建超级播放器def super_player(file_, loop): for i in range(2): print('start playing: %s !%s' % (file_...原创 2019-02-21 14:31:09 · 4704 阅读 · 2 评论 -
python3练习4:从txt或csv文件中读取数据并以字典存储返回
1、读取txt文件并返回字典文件内容如下:代码如下:#!/usr/bin/env python# coding=utf-8import codecsdef read_txt(path): txt_dict = {} with codecs.open(path, 'r', 'utf-8') as config: for line in c...原创 2018-12-24 22:47:54 · 11476 阅读 · 1 评论 -
8、webdriver的get_screenshot_as_file错误截图并保存到指定文件中
#!/usr/bin/env python# coding=utf-8from selenium import webdriverimport timefrom selenium.common.exceptions import NoSuchElementExceptiondriver = webdriver.Firefox()driver.get("https://baidu....原创 2018-12-27 21:09:53 · 2024 阅读 · 0 评论 -
2、python3+selenium之控制浏览器操作
0、打开浏览器: 打开火狐浏览器: driver = webdriver.Firefox() 打开IE浏览器: driver = webdriver.Ie() 打开Chrome浏览器: driver = webdriver.Chrome() 打开Safari浏览器: driver = webdriver.Safari()1、控制浏览器大小 dri...原创 2018-12-02 23:09:57 · 675 阅读 · 0 评论 -
3、python3+selenium之简单元素操作
1、clear():清除文本2、send_keys():模拟按键输入3、click():点击元素4、submit():用于提交表单,相当于“回车”操作 driver.find_element_by('kw').send_keys('selenium') driver.find_element_by('kw').submit() 5、size:获取输入框尺寸...原创 2018-12-02 23:19:37 · 256 阅读 · 0 评论 -
4、python3+selenium之键盘事件
引入Keys模块 from selenium.webdriver.commin.keys import Keys输入框输入内容 driver.find_elment_by_id("kw").send_keys('seleniumm')删除多输入的一个m driver.find_element_by_id('kw').send_keys(Keys.BACK_SPACE...原创 2018-12-02 23:32:09 · 941 阅读 · 1 评论 -
5、python+selenium之常见鼠标事件
需要引入的类:from selenium.webdriver.common.action_chains import ActionChains常用方法:perform() 执行所有的ActionChains中的存储行为 double_click() 双击 context_click() 右击 drag_and_drop(源元素,目标元素) 拖动 m...原创 2018-12-02 23:30:22 · 152 阅读 · 0 评论 -
练手3:unittest自动化测试框架+HTMLTestRunner测试报告
#!/usr/bin/env python# coding=utf-8# 文件名:test_case01.py# coding=utf-8import unittestfrom HTMLTestRunner import HTMLTestRunnerfrom datetime import datetimeclass TestCase01(unittest.TestCase):...原创 2018-12-07 20:27:22 · 267 阅读 · 0 评论 -
python3扩展HTMLTestRunner测试报告
原出处自:https://www.cnblogs.com/feiquan/p/8525903.html """A TestRunner for use with the Python unit testing framework. Itgenerates a HTML report to show the result at a glance.The simplest way to u...转载 2018-12-07 21:45:10 · 659 阅读 · 0 评论 -
6、python+selenium基础之多窗口和表单切换
一、多窗口切换:浏览器的句柄是表示浏览器某个窗口的唯一标识,只需要切换到对应句柄,就能打开对应的窗口页面获得当前窗口句柄 handle = driver.current_window_handle获得所有打开的窗口的句柄 all_handles = driver.window_handles切换到某个窗口 driver.switch_to.window(ha...原创 2018-12-08 17:20:34 · 310 阅读 · 0 评论 -
7、警告框处理:alertr对象
使用switch_to_alert()方法定位到alert/confirm/promptprompt:提示信息text = driver.switch_to_alert().text :返回alert/confirm/prompt中的文本信息driver.switch_to_alert().accept() :接收当前警告框driver.switch_to_alert().dismi...原创 2018-12-11 22:22:56 · 153 阅读 · 0 评论 -
练手1:python3+selenium
#!/usr/bin/env python# coding=utf-8from selenium import webdriverimport timefrom selenium.webdriver.support.ui import WebDriverWaitm = webdriver.Safari()def get_ele_times(driver, times, func)...原创 2018-12-06 21:53:47 · 298 阅读 · 0 评论 -
1、python3+selenium之常见的页面元素定位方法
一、ID定位 find_elemet_by_id("")二、name定位 find_element_by_name("")三、class定位 find_element_by_class_name("")四、tag定位 find_element_by_tag_name("") 五、link定位 find_element_by_link_t...原创 2018-12-02 23:08:05 · 576 阅读 · 0 评论