没有合适的资源?快使用搜索试试~ 我知道了~
selenium-python文档 selenium-python文档 selenium-python文档
资源推荐
资源详情
资源评论
Selenium Python Bindings
Release 2
Baiju Muthukadan
Nov 17, 2017
Contents
1 Installation 3
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Downloading Python bindings for Selenium . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Detailed instructions for Windows users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Downloading Selenium server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Getting Started 7
2.1 Simple Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Example Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Using Selenium to write tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Walk through of the example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Using Selenium with remote WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Navigating 13
3.1 Interacting with the page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Filling in forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Drag and drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.4 Moving between windows and frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5 Popup dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.6 Navigation: history and location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.7 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4 Locating Elements 17
4.1 Locating by Id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2 Locating by Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.3 Locating by XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.4 Locating Hyperlinks by Link Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.5 Locating Elements by Tag Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.6 Locating Elements by Class Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.7 Locating Elements by CSS Selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5 Waits 23
5.1 Explicit Waits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 Implicit Waits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6 Page Objects 27
i
6.1 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2 Page object classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.3 Page elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.4 Locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7 WebDriver API 31
7.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.2 Action Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
7.3 Alerts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
7.4 Special Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
7.5 Locate elements By . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.6 Desired Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.7 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.8 Firefox WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.9 Chrome WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.10 Remote WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.11 WebElement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.12 UI Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.13 Color Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.14 Expected conditions Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8 Appendix: Frequently Asked Questions 63
8.1 How to use ChromeDriver ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2 Does Selenium 2 support XPath 2.0 ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.3 How to scroll down to the bottom of a page ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.4 How to auto save files using custom Firefox profile ? . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.5 How to upload files into file inputs ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.6 How to use firebug with Firefox ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.7 How to take screenshot of the current window ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9 Indices and tables 67
Python Module Index 69
ii
Selenium Python Bindings, Release 2
Author Baiju Muthukadan
License This document is licensed under a Creative Commons Attribution-ShareAlike 4.0 International
License.
Note: This is not an official documentation. If you would like to contribute to this documentation, you can fork this
project in Github and send pull requests. You can also send your feedback to my email: baiju.m.mail AT gmail DOT
com. So far around 40 community members have contributed to this project (See the closed pull requests). I encourage
contributors to add more sections and make it a good documentation!
Contents 1
剩余81页未读,继续阅读
资源评论
BiggerFigure
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功