| 1 |
# WebDriver client for Python |
| 2 |
|
| 3 |
This package provides Python bindings |
| 4 |
that conform to the [W3C WebDriver standard](https://w3c.github.io/webdriver/), |
| 5 |
which specifies a remote control protocol for web browsers. |
| 6 |
|
| 7 |
These bindings are written with determining |
| 8 |
implementation compliance to the specification in mind, |
| 9 |
so that different remote end drivers |
| 10 |
can determine whether they meet the recognised standard. |
| 11 |
The client is used for the WebDriver specification tests |
| 12 |
in [web-platform-tests](https://github.com/web-platform-tests/wpt). |
| 13 |
|
| 14 |
## Installation |
| 15 |
|
| 16 |
To install the package individually |
| 17 |
in your virtualenv or system-wide: |
| 18 |
|
| 19 |
% python setup.py install |
| 20 |
|
| 21 |
Since this package does not have any external dependencies, |
| 22 |
you can also use the client directly from the checkout directory, |
| 23 |
which is useful if you want to contribute patches back: |
| 24 |
|
| 25 |
% cd /path/to/wdclient |
| 26 |
% python |
| 27 |
Python 2.7.12+ (default, Aug 4 2016, 20:04:34) |
| 28 |
[GCC 6.1.1 20160724] on linux2 |
| 29 |
Type "help", "copyright", "credits" or "license" for more information. |
| 30 |
>>> import webdriver |
| 31 |
>>> |
| 32 |
|
| 33 |
If you are writing WebDriver specification tests for |
| 34 |
[WPT](https://github.com/web-platform-tests/wpt), |
| 35 |
there is no need to install the client manually |
| 36 |
as it is included in the `tools/webdriver` directory. |
| 37 |
|
| 38 |
## Usage |
| 39 |
|
| 40 |
You can use the built-in |
| 41 |
[context manager](https://docs.python.org/2/reference/compound_stmts.html#the-with-statement) |
| 42 |
to manage the lifetime of the session. |
| 43 |
The session is started implicitly |
| 44 |
at the first call to a command if it has not already been started, |
| 45 |
and will implicitly be ended when exiting the context: |
| 46 |
|
| 47 |
```py |
| 48 |
import webdriver |
| 49 |
|
| 50 |
with webdriver.Session("127.0.0.1", 4444) as session: |
| 51 |
session.url = "https://mozilla.org" |
| 52 |
print "The current URL is %s" % session.url |
| 53 |
``` |
| 54 |
|
| 55 |
The following is functionally equivalent to the above, |
| 56 |
but giving you manual control of the session: |
| 57 |
|
| 58 |
```py |
| 59 |
import webdriver |
| 60 |
|
| 61 |
session = webdriver.Session("127.0.0.1", 4444) |
| 62 |
session.start() |
| 63 |
|
| 64 |
session.url = "https://mozilla.org" |
| 65 |
print "The current URL is %s" % session.url |
| 66 |
|
| 67 |
session.end() |
| 68 |
``` |
| 69 |
|
| 70 |
## Dependencies |
| 71 |
|
| 72 |
This client has the benefit of only using standard library dependencies. |
| 73 |
No external PyPI dependencies are needed. |