selenium webdriver (python)(第三版) 目录 一、selenium+python 环境搭建................................................................................................6 1.1 selenium 介绍............................................................................................................... 6 1.2 准备工作......................................... .............................................................................6 1.3 安装步骤......................................................................................................................7 1.4 安装chrome driver...................................................................................................... 8 1.5 安装IE driver................................................................................ 9 二、开始第一个脚本.................................................................................................................9 2.1 为什么选python..........................................................................................................9 2.2 第一个脚本..................................................................................................................9 2.3 脚本解析....................................................................................................................10 三、元素的定位....................................................................................................................... 11 3.1 id 和name 定位.......................................................................................................12 3.2 tag name 和class name 定位...................................................................................12 3.3 CSS 定位..................................................................................................................13 3.4 XPath 定位...............................................................................................................14 3.5 link 定位...................................................................................................................15 3.6 Partial link text 定位................................................................................................ 15 四、添加等待时间...................................................................................................................15 4.1、添加休眠..................................................................................................................15 4.2、智能等待..................................................................................................................16 五、打印信息...........................................................................................................................17 5.1、打印tile....................................................................................................................17 5.2、打印URL.................................................................................................................17 六、浏览器的操作...................................................................................................................18 6.1、浏览器最大化..........................................................................................................18 6.2、设置浏览器宽、高..................................................................................................19 七、操作浏览器的前进、后退...............................................................................................19 八、操作测试对象...................................................................................................................20 8.1、鼠标点击与键盘输入..............................................................................................21 8.2、submit 提交表单......................................................................................................21 8.3、text 获取元素文本...................................................................................................22 8.4、get_attribute 获得属性值........................................................................................ 22 九、键盘事件...........................................................................................................................23 9.1、键盘按键用法..........................................................................................................23 9.2、键盘组合键用法......................................................................................................24 9.3、中文乱码问题..........................................................................................................25 十、鼠标事件...........................................................................................................................25 10.1、鼠标右键................................................................................................................26 博客园—虫师 http://4 fnng.cnblogs.com 10.2、鼠标双击................................................................................................................27 10.3、鼠标拖放................................................................................................................27 十一、定位一组元素...............................................................................................................28 11.1、第一种定位方法....................................................................................................30 11.2、第二种定位方法....................................................................................................31 11.3、去掉最后一个勾选................................................................................................31 十二、多层框架/窗口定位......................................................................................................32 12.1、多层框架定位........................................................................................................32 12.2、多层窗口定位........................................................................................................35 十三、层级定位.......................................................................................................................35 十四、上传文件操作...............................................................................................................38 14.1、操作文件上传例子................................................................................................39 14.2、139 邮箱上传.........................................................................................................40 十五、下拉框处理...................................................................................................................41 15.1、操作下拉框例子....................................................................................................41 15.2、百度搜索设置下拉框操作....................................................................................43 十六、alert、confirm、prompt 的处理.................................................................................. 44 十七、对话框的处理...............................................................................................................45 17.1、div 对话框的处理..................................................................................................45 17.2、一般对话框的处理................................................................................................48 十八、调用js........................................................................................................................... 49 18.1、通过js 隐藏元素................................................................................................... 49 18.2、通过js 使输入框标红...........................................................................................51 十九、控制浏览器滚动条.......................................................................................................52 19.1、场景一....................................................................................................................53 19.2、场景二....................................................................................................................53 二十、cookie 处理................................................................................................................... 54 20.1、打印cookie 信息................................................................................................... 54 20.2、对cookie 操作....................................................................................................... 55 20.3、博客园登陆分析cookie........................................................................................56 二十一、webdriver 原理解析................................................................................................. 57 二十二、引入unittest 框架.....................................................................................................65 二十三、unittest 单元测试框架解析......................................................................................70 二十四、批量执行测试集.......................................................................................................75 二十五、异常捕捉与错误截图...............................................................................................77 二十六、生成测试报告(HTMLTestRunner).......................................................................... 80 二十七、数据驱动测试...........................................................................................................83 27.1、读取文件参数化....................................................................................................83 27.2、用户名密码的参数化(读取文件)................................................................... 85 27.3、用户名的参数化(字典)....................................................................................86 27.4、用户名密码的参数化(函数)........................................................................... 87 二十八、测试套件...................................................................................................................89 28.1、测试套件实例........................................................................................................89 28.2、整合HTMLTestRunner 测试报告........................................................................ 93 博客园—虫师 http://5 fnng.cnblogs.com 28.3、更易读的报告........................................................................................................95 二十九、结构改进...................................................................................................................96 29.1、all_tests.py 移出来................................................................................................96 29.2、__init__.py 文件解析............................................................................................ 97 29.3、调用多级目录的用例............................................................................................98 29.4、改进用例的读取....................................................................................................99 29.5、进一步分离用例列表..........................................................................................101 三十、UliPad--python 开发利器...........................................................................................103 .............................................................................6 1.3 安装步骤......................................................................................................................7 1.4 安装chrome driver...................................................................................................... 8 1.5 安装IE driver................................................................................ 9 二、开始第一个脚本.................................................................................................................9 2.1 为什么选python..........................................................................................................9 2.2 第一个脚本..................................................................................................................9 2.3 脚本解析....................................................................................................................10 三、元素的定位....................................................................................................................... 11 3.1 id 和name 定位.......................................................................................................12 3.2 tag name 和class name 定位...................................................................................12 3.3 CSS 定位..................................................................................................................13 3.4 XPath 定位...............................................................................................................14 3.5 link 定位...................................................................................................................15 3.6 Partial link text 定位................................................................................................ 15 四、添加等待时间...................................................................................................................15 4.1、添加休眠..................................................................................................................15 4.2、智能等待..................................................................................................................16 五、打印信息...........................................................................................................................17 5.1、打印tile....................................................................................................................17 5.2、打印URL.................................................................................................................17 六、浏览器的操作...................................................................................................................18 6.1、浏览器最大化..........................................................................................................18 6.2、设置浏览器宽、高..................................................................................................19 七、操作浏览器的前进、后退...............................................................................................19 八、操作测试对象...................................................................................................................20 8.1、鼠标点击与键盘输入..............................................................................................21 8.2、submit 提交表单......................................................................................................21 8.3、text 获取元素文本...................................................................................................22 8.4、get_attribute 获得属性值........................................................................................ 22 九、键盘事件...........................................................................................................................23 9.1、键盘按键用法..........................................................................................................23 9.2、键盘组合键用法......................................................................................................24 9.3、中文乱码问题..........................................................................................................25 十、鼠标事件...........................................................................................................................25 10.1、鼠标右键................................................................................................................26 博客园—虫师 http://4 fnng.cnblogs.com 10.2、鼠标双击................................................................................................................27 10.3、鼠标拖放................................................................................................................27 十一、定位一组元素...............................................................................................................28 11.1、第一种定位方法....................................................................................................30 11.2、第二种定位方法....................................................................................................31 11.3、去掉最后一个勾选................................................................................................31 十二、多层框架/窗口定位......................................................................................................32 12.1、多层框架定位........................................................................................................32 12.2、多层窗口定位........................................................................................................35 十三、层级定位.......................................................................................................................35 十四、上传文件操作...............................................................................................................38 14.1、操作文件上传例子................................................................................................39 14.2、139 邮箱上传.........................................................................................................40 十五、下拉框处理...................................................................................................................41 15.1、操作下拉框例子....................................................................................................41 15.2、百度搜索设置下拉框操作....................................................................................43 十六、alert、confirm、prompt 的处理.................................................................................. 44 十七、对话框的处理...............................................................................................................45 17.1、div 对话框的处理..................................................................................................45 17.2、一般对话框的处理................................................................................................48 十八、调用js........................................................................................................................... 49 18.1、通过js 隐藏元素................................................................................................... 49 18.2、通过js 使输入框标红...........................................................................................51 十九、控制浏览器滚动条.......................................................................................................52 19.1、场景一....................................................................................................................53 19.2、场景二....................................................................................................................53 二十、cookie 处理................................................................................................................... 54 20.1、打印cookie 信息................................................................................................... 54 20.2、对cookie 操作....................................................................................................... 55 20.3、博客园登陆分析cookie........................................................................................56 二十一、webdriver 原理解析................................................................................................. 57 二十二、引入unittest 框架.....................................................................................................65 二十三、unittest 单元测试框架解析......................................................................................70 二十四、批量执行测试集.......................................................................................................75 二十五、异常捕捉与错误截图...............................................................................................77 二十六、生成测试报告(HTMLTestRunner).......................................................................... 80 二十七、数据驱动测试...........................................................................................................83 27.1、读取文件参数化....................................................................................................83 27.2、用户名密码的参数化(读取文件)................................................................... 85 27.3、用户名的参数化(字典)....................................................................................86 27.4、用户名密码的参数化(函数)........................................................................... 87 二十八、测试套件...................................................................................................................89 28.1、测试套件实例........................................................................................................89 28.2、整合HTMLTestRunner 测试报告........................................................................ 93 博客园—虫师 http://5 fnng.cnblogs.com 28.3、更易读的报告........................................................................................................95 二十九、结构改进...................................................................................................................96 29.1、all_tests.py 移出来................................................................................................96 29.2、__init__.py 文件解析............................................................................................ 97 29.3、调用多级目录的用例............................................................................................98 29.4、改进用例的读取....................................................................................................99 29.5、进一步分离用例列表..........................................................................................101 三十、UliPad--python 开发利器...........................................................................................103