Selenium Python Readthedocs Io en Latest
Selenium Python Readthedocs Io en Latest
Release 2
Baiju Muthukadan
1 Installation 3
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Installing Python bindings for Selenium . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Instructions for Windows users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Installing from Git sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Downloading Selenium server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Getting Started 7
2.1 Simple Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Example Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Using Selenium to write tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Walkthrough of the example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Using Selenium with remote WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
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
6.1 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2 Page object classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.3 Page elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
i
6.4 Locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7 WebDriver API 31
7.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.2 Action Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
7.3 Alerts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.4 Special Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.5 Locate elements By . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.6 Desired Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.7 Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.8 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.9 Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.10 Application Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.11 Firefox WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.12 Firefox WebDriver Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.13 Firefox WebDriver Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.14 Firefox WebDriver Binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.15 Firefox WebDriver Extension Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.16 Chrome WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.17 Chrome WebDriver Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.18 Chrome WebDriver Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7.19 Remote WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7.20 Remote WebDriver WebElement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.21 Remote WebDriver Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.22 Remote WebDriver Error Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7.23 Remote WebDriver Mobile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.24 Remote WebDriver Remote Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
7.25 Remote WebDriver Utils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.26 Internet Explorer WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.27 Safari WebDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.28 Safari WebDriver Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.29 Select Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.30 Wait Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.31 Color Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.32 Event Firing WebDriver Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.33 Abstract Event Listener Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.34 Expected conditions Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Index 101
ii
Selenium Python Bindings, Release 2
Author
Baiju Muthukadan
License
This document is licensed under a Creative Commons Attribution-ShareAlike 4.0 International Li-
cense.
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 60+ community members have contributed to this project (See the closed pull requests). I encourage
contributors to add more sections and make it an awesome documentation! If you know any translation of this document,
please send a PR to update the below list.
Translations:
• Chinese
• Japanese
CONTENTS 1
Selenium Python Bindings, Release 2
2 CONTENTS
CHAPTER
ONE
INSTALLATION
1.1 Introduction
Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver.
Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way.
Selenium Python bindings provide a convenient API to access Selenium WebDrivers like Firefox, Ie, Chrome, Remote
etc. The current supported Python versions are 3.5 and above.
This documentation explains Selenium 2 WebDriver API. Selenium 1 / Selenium RC API is not covered here.
Use pip to install the selenium package. Python 3 has pip available in the standard library. Using pip, you can install
selenium like this:
You may consider using virtualenv to create isolated Python environments. Python 3 has venv which is almost the same
as virtualenv.
You can also download Python bindings for Selenium from the PyPI page for selenium package. and install manually.
Now you can run your test scripts using Python. For example, if you have created a Selenium based script and saved it
inside C:\my_selenium_script.py, you can run it like this:
C:\Python39\python.exe C:\my_selenium_script.py
3
Selenium Python Bindings, Release 2
To build Selenium Python from the source code, clone the official repository. It contains the source code for all official
Selenium flavors, like Python, Java, Ruby and others. The Python code resides in the /py directory. To build, you will
also need the Bazel build system.
Note: Currently, as Selenium gets near to the 4.0.0 release, it requires Bazel 3.2.0 (Install instructions), even though
3.3.0 is already available.
To build a Wheel from the sources, run the following command from the repository root:
bazel //py:selenium-wheel
This command will prepare the source code with some preprocessed JS files needed by some webdriver modules and
build the .whl package inside the ./bazel-bin/py/ directory. Afterwards, you can use pip to install it.
1.5 Drivers
Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which
needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or
/usr/local/bin.
Failure to observe this step will give you an error selenium.common.exceptions.WebDriverException: Message: ‘geck-
odriver’ executable needs to be in PATH.
Other supported browsers will have their own drivers available. Links to some of the more popular browser drivers
follow.
Chrome: https://sites.google.com/chromium.org/driver/
Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox: https://github.com/mozilla/geckodriver/releases
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/
For more information about driver installation, please refer the official documentation.
Starting from version 4.6.0 (November 4, 2022) selenium comes with Selenium Manager packed in distribution.
Selenium Manager is a new tool that helps to get a working environment to run Selenium out of the box:
• automatically discovers, downloads, and caches the drivers required by Selenium when these drivers are
unavailable;
• automatically discovers, downloads, and caches the browsers driven with Selenium (Chrome, Firefox, and
Edge) when these browsers are not installed in the local system.
For example, to see the result of Selenium Manager work just run any selenium script without previous driver setup
and explore ~/.cache/selenium.
More about Selenium Manager you can read in the documentation and blog.
4 Chapter 1. Installation
Selenium Python Bindings, Release 2
Note: The Selenium server is only required if you want to use the remote WebDriver. See the Using Selenium
with remote WebDriver section for more details. If you are a beginner learning Selenium, you can skip this section and
proceed with next chapter.
Selenium server is a Java program. Java Runtime Environment (JRE) 1.6 or newer version is recommended to run
Selenium server.
You can download Selenium server 2.x from the download page of selenium website. The file name should be something
like this: selenium-server-standalone-2.x.x.jar. You can always download the latest 2.x version of Selenium
server.
If Java Runtime Environment (JRE) is not installed in your system, you can download the JRE from the Oracle website.
If you are using a GNU/Linux system and have root access in your system, you can also use your operating system
instructions to install JRE.
If java command is available in the PATH (environment variable), you can start the Selenium server using this com-
mand:
Replace 2.x.x with the actual version of Selenium server you downloaded from the site.
If JRE is installed as a non-root user and/or if it is not available in the PATH (environment variable), you can type the
relative or absolute path to the java command. Similarly, you can provide a relative or absolute path to Selenium server
jar file. Then, the command will look something like this:
6 Chapter 1. Installation
CHAPTER
TWO
GETTING STARTED
If you have installed Selenium Python bindings, you can start using it from Python like this.
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element(By.NAME, "q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
The above script can be saved into a file (eg:- python_org_search.py), then it can be run like this:
python python_org_search.py
The python which you are running should have the selenium module installed.
The selenium.webdriver module provides all the WebDriver implementations. Currently supported WebDriver imple-
mentations are Firefox, Chrome, IE and Remote. The Keys class provide keys in the keyboard like RETURN, F1, ALT
etc. The By class is used to locate elements within a document.
driver = webdriver.Firefox()
7
Selenium Python Bindings, Release 2
The driver.get method will navigate to a page given by the URL. WebDriver will wait until the page has fully loaded
(that is, the “onload” event has fired) before returning control to your test or script. Be aware that if your page uses a
lot of AJAX on load then WebDriver may not know when it has completely loaded:
driver.get("http://www.python.org")
The next line is an assertion to confirm that title has the word “Python” in it:
WebDriver offers a number of ways to find elements using the find_element method. For example, the input text
element can be located by its name attribute using the find_element method and using By.NAME as its first parameter.
A detailed explanation of finding elements is available in the Locating Elements chapter:
Next, we are sending keys, this is similar to entering keys using your keyboard. Special keys can be sent using the Keys
class imported from selenium.webdriver.common.keys. To be safe, we’ll first clear any pre-populated text in the input
field (e.g. “Search”) so it doesn’t affect our search results:
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
After submission of the page, you should get the result if there is any. To ensure that some results are found, make an
assertion:
Finally, the browser window is closed. You can also call the quit method instead of close. The quit method will exit
the browser whereas close will close one tab, but if just one tab was open, by default most browsers will exit entirely.:
driver.close()
Selenium is mostly used for writing test cases. The selenium package itself doesn’t provide a testing tool/framework.
You can write test cases using Python’s unittest module. Alternatively, you may consider pytest for writing tests.
In this chapter, we use unittest as the framework of choice. Here is the modified example which uses the unittest module.
This is a test for the python.org search functionality:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
(continues on next page)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
You can run the above test case from a shell like this:
python test_python_org_search.py
.
----------------------------------------------------------------------
Ran 1 test in 15.566s
OK
The above result shows that the test has been successfully completed.
Note: To run the above test in IPython or Jupyter, you should pass a couple of arguments to the main function as shown
below:
unittest.main(argv=['first-arg-is-ignored'], exit=False)
Initially, all the basic modules required are imported. The unittest module is a built-in Python module based on Java’s
JUnit. This module provides the framework for organizing the test cases. The selenium.webdriver module provides
all the WebDriver implementations. Currently supported WebDriver implementations are: Firefox, Chrome, IE and
Remote. The Keys class provides keys in the keyboard like RETURN, F1, ALT etc. The By class is used to locate
elements within a document.
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
The test case class is inherited from unittest.TestCase. Inheriting from the TestCase class is the way to tell unittest
module that this is a test case:
class PythonOrgSearch(unittest.TestCase):
The setUp method is part of initialization. This method will get called before every test function which you are going
to write in this test case class. Here you are creating an instance of a Firefox WebDriver.
def setUp(self):
self.driver = webdriver.Firefox()
This is the test case method. The test case method should always start with characters test. The first line inside this
method creates a local reference to the driver object created in setUp method.
def test_search_in_python_org(self):
driver = self.driver
The driver.get method will navigate to a page given by the URL. WebDriver will wait until the page has fully loaded
(that is, the “onload” event has fired) before returning control to your test or script. Be aware that if your page uses a
lot of AJAX on load then WebDriver may not know when it has completely loaded:
driver.get("http://www.python.org")
The next line is an assertion to confirm that title has the word “Python” in it:
self.assertIn("Python", driver.title)
WebDriver offers a number of ways to find elements using the find_element method. For example, the input text
element can be located by its name attribute using the find_element method. Detailed explanation of finding elements
is available in the Locating Elements chapter:
Next, we are sending keys, this is similar to entering keys using your keyboard. Special keys can be sent using the Keys
class imported from selenium.webdriver.common.keys:
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
After submission of the page, you should get the result as per search if there is any. To ensure that some results are
found, make an assertion:
The tearDown method will get called after every test method. This is a place to do all cleanup actions. In the current
method, the browser window is closed. You can also call the quit method instead of close. The quit method will exit
the entire browser, whereas close will close a tab, but if it is the only tab opened, by default most browsers will exit
entirely.:
def tearDown(self):
self.driver.close()
Final lines are some boiler plate code to run the test suite:
if __name__ == "__main__":
unittest.main()
To use the remote WebDriver, you should have the Selenium server running. To run the server, use this command:
While running the Selenium server, you could see a message looking like this:
The above line says that you can use this URL for connecting to the remote WebDriver. Here are some examples:
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
options=webdriver.ChromeOptions()
)
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
options=webdriver.FirefoxOptions()
)
THREE
NAVIGATING
The first thing you’ll want to do with WebDriver is navigate to a link. The normal way to do this is by calling get
method:
driver.get("http://www.google.com")
WebDriver will wait until the page has fully loaded (that is, the onload event has fired) before returning control to
your test or script. Be aware that if your page uses a lot of AJAX on load then WebDriver may not know when it has
completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more
specifically, the HTML elements within a page. First of all, we need to find one. WebDriver offers a number of ways
to find elements. For example, given an element defined as:
You can also look for a link by its text, but be careful! The text must be an exact match! You should also be careful
when using XPATH in WebDriver. If there’s more than one element that matches the query, then only the first will be
returned. If nothing can be found, a NoSuchElementException will be raised.
WebDriver has an “Object-based” API; we represent all types of elements using the same interface. This means that
although you may see a lot of possible methods you could invoke when you hit your IDE’s auto-complete key combi-
nation, not all of them will make sense or be valid. Don’t worry! WebDriver will attempt to do the Right Thing, and if
you call a method that makes no sense (“setSelected()” on a “meta” tag, for example) an exception will be raised.
So, you’ve got an element. What can you do with it? First of all, you may want to enter some text into a text field:
element.send_keys("some text")
You can simulate pressing the arrow keys by using the “Keys” class:
13
Selenium Python Bindings, Release 2
It is possible to call send_keys on any element, which makes it possible to test keyboard shortcuts such as those used
on GMail. A side-effect of this is that typing something into a text field won’t automatically clear it. Instead, what you
type will be appended to what’s already there. You can easily clear the contents of a text field or textarea with the clear
method:
element.clear()
We’ve already seen how to enter text into a textarea or text field, but what about the other elements? You can “toggle”
the state of the drop down, and you can use “setSelected” to set something like an OPTION tag selected. Dealing with
SELECT tags isn’t too bad:
This will find the first “SELECT” element on the page, and cycle through each of its OPTIONs in turn, printing out
their values, and selecting each in turn.
As you can see, this isn’t the most efficient way of dealing with SELECT elements. WebDriver’s support classes include
one called a “Select”, which provides useful methods for interacting with these:
WebDriver also provides features for deselecting all the selected options:
This will deselect all OPTIONs from that particular SELECT on the page.
Suppose in a test, we need the list of all default selected options, Select class provides a property method that returns
a list:
options = select.options
Once you’ve finished filling out the form, you probably want to submit it. One way to do this would be to find the
“submit” button and click it:
14 Chapter 3. Navigating
Selenium Python Bindings, Release 2
Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within
a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. If the element
isn’t in a form, then the NoSuchElementException will be raised:
element.submit()
You can use drag and drop, either moving an element by a certain amount, or on to another element:
It’s rare for a modern web application not to have any frames or to be constrained to a single window. WebDriver
supports moving between named windows using the “switch_to.window” method:
driver.switch_to.window("windowName")
All calls to driver will now be interpreted as being directed to the particular window. But how do you know the
window’s name? Take a look at the javascript or link that opened it:
Alternatively, you can pass a “window handle” to the “switch_to.window()” method. Knowing this, it’s possible to
iterate over every open window like so:
You can also swing from frame to frame (or into iframes):
driver.switch_to.frame("frameName")
It’s possible to access subframes by separating the path with a dot, and you can specify the frame by its index too. That
is:
driver.switch_to.frame("frameName.0.child")
would go to the frame named “child” of the first subframe of the frame called “frameName”. All frames are evaluated
as if from *top*.
Once we are done with working on frames, we will have to come back to the parent frame which can be done using:
driver.switch_to.default_content()
Selenium WebDriver has built-in support for handling popup dialog boxes. After you’ve triggered action that would
open a popup, you can access the alert with the following:
alert = driver.switch_to.alert
This will return the currently open alert object. With this object, you can now accept, dismiss, read its contents or even
type into a prompt. This interface works equally well on alerts, confirms, prompts. Refer to the API documentation for
more information.
driver.get("http://www.example.com")
driver.forward()
driver.back()
Please be aware that this functionality depends entirely on the underlying driver. It’s just possible that something
unexpected may happen when you call these methods if you’re used to the behavior of one browser over another.
3.7 Cookies
Before moving to the next section of the tutorial, you may be interested in understanding how to use cookies. First of
all, you need to be on the domain that the cookie will be valid for:
# Now set the cookie. This one's valid for the entire domain
cookie = {'name' : 'foo', 'value' : 'bar'}
driver.add_cookie(cookie)
# And now output all the available cookies for the current URL
driver.get_cookies()
16 Chapter 3. Navigating
CHAPTER
FOUR
LOCATING ELEMENTS
There are various strategies to locate elements in a page. You can use the most appropriate one for your case. Selenium
provides the following method to locate elements in a page:
• find_element
To find multiple elements (these methods will return a list):
• find_elements
Example usage:
The attributes available for the By class are used to locate elements on a page. These are the attributes available for By
class:
ID = "id"
NAME = "name"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
The ‘By’ class is used to specify which attribute is used to locate elements on a page. These are the various ways the
attributes are used to locate elements on a page:
find_element(By.ID, "id")
find_element(By.NAME, "name")
find_element(By.XPATH, "xpath")
find_element(By.LINK_TEXT, "link text")
find_element(By.PARTIAL_LINK_TEXT, "partial link text")
find_element(By.TAG_NAME, "tag name")
find_element(By.CLASS_NAME, "class name")
find_element(By.CSS_SELECTOR, "css selector")
If you want to locate several elements with the same attribute replace find_element with find_elements.
17
Selenium Python Bindings, Release 2
4.1 Locating by Id
Use this when you know the id attribute of an element. With this strategy, the first element with a matching id attribute
will be returned. If no element has a matching id attribute, a NoSuchElementException will be raised.
For instance, consider this page source:
<html>
<body>
<form id="loginForm">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="continue" type="submit" value="Login" />
</form>
</body>
</html>
Use this when you know the name attribute of an element. With this strategy, the first element with a matching name
attribute will be returned. If no element has a matching name attribute, a NoSuchElementException will be raised.
For instance, consider this page source:
<html>
<body>
<form id="loginForm">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="continue" type="submit" value="Login" />
<input name="continue" type="button" value="Clear" />
</form>
</body>
</html>
This will give the “Login” button as it occurs before the “Clear” button:
XPath is the language used for locating nodes in an XML document. As HTML can be an implementation of XML
(XHTML), Selenium users can leverage this powerful language to target elements in their web applications. XPath
supports the simple methods of locating by id or name attributes and extends them by opening up all sorts of new
possibilities such as locating the third checkbox on the page.
One of the main reasons for using XPath is when you don’t have a suitable id or name attribute for the element you
wish to locate. You can use XPath to either locate the element in absolute terms (not advised), or relative to an element
that does have an id or name attribute. XPath locators can also be used to specify elements via attributes other than id
and name.
Absolute XPaths contain the location of all elements from the root (html) and as a result are likely to fail with only
the slightest adjustment to the application. By finding a nearby element with an id or name attribute (ideally a parent
element) you can locate your target element based on the relationship. This is much less likely to change and can make
your tests more robust.
For instance, consider this page source:
<html>
<body>
<form id="loginForm">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="continue" type="submit" value="Login" />
<input name="continue" type="button" value="Clear" />
</form>
</body>
</html>
1. Absolute path (would break if the HTML was changed only slightly)
2. First form element in the HTML
3. The form element with attribute id set to loginForm
The username element can be located like this:
1. First form element with an input child element with name set to username
2. First input child element of the form element with attribute id set to loginForm
3. First input element with attribute name set to username
The “Clear” button element can be located like this:
1. Input with attribute name set to continue and attribute type set to button
2. Fourth input child element of the form element with attribute id set to loginForm
These examples cover some basics, but in order to learn more, the following references are recommended:
• W3Schools XPath Tutorial
• W3C XPath Recommendation
• XPath Tutorial - with interactive examples.
Here is a couple of very useful Add-ons that can assist in discovering the XPath of an element:
• xPath Finder - Plugin to get the elements xPath.
• XPath Helper - for Google Chrome
Use this when you know the link text used within an anchor tag. With this strategy, the first element with
the link text matching the provided value will be returned. If no element has a matching link text attribute, a
NoSuchElementException will be raised.
For instance, consider this page source:
<html>
<body>
<p>Are you sure you want to do this?</p>
<a href="continue.html">Continue</a>
<a href="cancel.html">Cancel</a>
</body>
</html>
Use this when you want to locate an element by tag name. With this strategy, the first element with the given tag name
will be returned. If no element has a matching tag name, a NoSuchElementException will be raised.
For instance, consider this page source:
<html>
<body>
<h1>Welcome</h1>
<p>Site content goes here.</p>
</body>
</html>
Use this when you want to locate an element by class name. With this strategy, the first element with the matching class
name attribute will be returned. If no element has a matching class name attribute, a NoSuchElementException will
be raised.
For instance, consider this page source:
<html>
<body>
<p class="content">Site content goes here.</p>
</body>
</html>
Use this when you want to locate an element using CSS selector syntax. With this strategy, the first element matching the
given CSS selector will be returned. If no element matches the provided CSS selector, a NoSuchElementException
will be raised.
For instance, consider this page source:
<html>
<body>
<p class="content">Site content goes here.</p>
</body>
</html>
FIVE
WAITS
These days, most of the web apps are using AJAX techniques. When a page is loaded by the browser, the elements
within that page may load at different time intervals. This makes locating elements difficult: if an element is not yet
present in the DOM, a locate function will raise an ElementNotVisibleException exception. Using waits, we can solve
this issue. Waiting provides some slack between actions performed - mostly locating an element or any other operation
with the element.
Selenium Webdriver provides two types of waits - implicit & explicit. An explicit wait makes WebDriver wait for a
certain condition to occur before proceeding further with execution. An implicit wait makes WebDriver poll the DOM
for a certain amount of time when trying to locate an element.
An explicit wait is a code you define to wait for a certain condition to occur before proceeding further in the code.
The extreme case of this is time.sleep(), which sets the condition to an exact time period to wait. There are some
convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in
combination with ExpectedCondition is one way this can be accomplished.
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
In the code above, Selenium will wait for a maximum of 10 seconds for an element matching the given criteria to
be found. If no element is found in that time, a TimeoutException is thrown. By default, WebDriverWait calls the
ExpectedCondition every 500 milliseconds until it returns success. ExpectedCondition will return true (Boolean) in
case of success or not null if it fails to locate an element.
Expected Conditions
There are some common conditions that are frequently of use when automating web browsers. Listed below are
the names of each. Selenium Python binding provides some convenience methods so you don’t have to code an ex-
pected_condition class yourself or create your own utility package for them.
23
Selenium Python Bindings, Release 2
• title_is
• title_contains
• presence_of_element_located
• visibility_of_element_located
• visibility_of
• presence_of_all_elements_located
• text_to_be_present_in_element
• text_to_be_present_in_element_value
• frame_to_be_available_and_switch_to_it
• invisibility_of_element_located
• element_to_be_clickable
• staleness_of
• element_to_be_selected
• element_located_to_be_selected
• element_selection_state_to_be
• element_located_selection_state_to_be
• alert_is_present
from selenium.webdriver.support import expected_conditions as EC
The expected_conditions module contains a set of predefined conditions to use with WebDriverWait.
Custom Wait Conditions
You can also create custom wait conditions when none of the previous convenience methods fit your requirements.
A custom wait condition can be created using a class with __call__ method which returns False when the condition
doesn’t match.
class element_has_css_class(object):
"""An expectation for checking that an element has a particular css class.
24 Chapter 5. Waits
Selenium Python Bindings, Release 2
An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or
elements) not immediately available. The default setting is 0 (zero). Once set, the implicit wait is set for the life of the
WebDriver object.
driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get("http://somedomain/url_that_delays_loading")
myDynamicElement = driver.find_element_by_id("myDynamicElement")
26 Chapter 5. Waits
CHAPTER
SIX
PAGE OBJECTS
This chapter is a tutorial introduction to the Page Objects design pattern. A page object represents an area where the
test interacts within the web application user interface.
Benefits of using page object pattern:
• Easy to read test cases
• Creating reusable code that can share across multiple test cases
• Reducing the amount of duplicated code
• If the user interface changes, the fix needs changes in only one place
Here is a test case that searches for a word on the python.org website and ensures some results. The following section
will introduce the page module where the page objects will be defined.
import unittest
from selenium import webdriver
import page
class PythonOrgSearch(unittest.TestCase):
"""A sample test class to show how page object works"""
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("http://www.python.org")
def test_search_in_python_org(self):
"""Tests python.org search feature. Searches for the word "pycon" then
verified that some results show up. Note that it does not look for
any particular text in search results page. This test verifies that
the results were not empty."""
#Load the main page. In this case the home page of Python.org.
main_page = page.MainPage(self.driver)
#Checks if the word "Python" is in title
self.assertTrue(main_page.is_title_matches(), "python.org title doesn't match.")
#Sets the text of search textbox to "pycon"
main_page.search_text_element = "pycon"
(continues on next page)
27
Selenium Python Bindings, Release 2
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
The page object pattern intends to create an object for each part of a web page. This technique helps build a separation
between the test code and the actual code that interacts with the web page.
The page.py will look like this:
from element import BasePageElement
from locators import MainPageLocators
class SearchTextElement(BasePageElement):
"""This class gets the search text from the specified locator"""
class BasePage(object):
"""Base class to initialize the base page that will be called from all
pages"""
class MainPage(BasePage):
"""Home page action methods come here. I.e. Python.org"""
def is_title_matches(self):
"""Verifies that the hardcoded text "Python" appears in page title"""
def click_go_button(self):
"""Triggers the search"""
element = self.driver.find_element(*MainPageLocators.GO_BUTTON)
(continues on next page)
class SearchResultsPage(BasePage):
"""Search results page action methods come here"""
def is_results_found(self):
# Probably should search for this text in the specific page
# element, but as for now it works fine
return "No results found." not in self.driver.page_source
class BasePageElement(object):
"""Base page class that is initialized on every page object class."""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element(By.NAME, self.locator))
driver.find_element(By.NAME, self.locator).clear()
driver.find_element(By.NAME, self.locator).send_keys(value)
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element(By.NAME, self.locator))
element = driver.find_element(By.NAME, self.locator)
return element.get_attribute("value")
6.4 Locators
One of the practices is to separate the locator strings from the place where they are getting used. In this example,
locators of the same page belong to the same class.
The locators.py will look like this:
class MainPageLocators(object):
"""A class for main page locators. All main page locators should come here"""
class SearchResultsPageLocators(object):
"""A class for search results locators. All search results locators should
come here"""
pass
SEVEN
WEBDRIVER API
Note: This is not an official documentation. Official API documentation is available here.
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.FirefoxOptions
webdriver.FirefoxService
webdriver.Chrome
webdriver.ChromeOptions
webdriver.ChromeService
webdriver.Ie
webdriver.IeOptions
webdriver.IeService
webdriver.Edge
webdriver.ChromiumEdge
webdriver.EdgeOptions
webdriver.EdgeService
webdriver.Safari
webdriver.SafariOptions
webdriver.SafariService
webdriver.WebKitGTK
webdriver.WebKitGTKOptions
webdriver.WebKitGTKService
webdriver.WPEWebKit
webdriver.WPEWebKitOptions
webdriver.WPEWebKitService
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
(continues on next page)
31
Selenium Python Bindings, Release 2
The exception classes can be imported like this (Replace the TheNameOfTheExceptionClass with the actual class
name given below):
driver.current_url
driver.close()
7.1 Exceptions
Bases: InvalidElementStateException
Thrown when an element is present in the DOM but interactions with that element will hit another element due
to paint order.
exception selenium.common.exceptions.ElementNotSelectableException(msg: str | None = None,
screen: str | None = None,
stacktrace: Sequence[str] |
None = None)
Bases: InvalidElementStateException
Thrown when trying to select an unselectable element.
For example, selecting a ‘script’ element.
exception selenium.common.exceptions.ElementNotVisibleException(msg: str | None = None, screen:
str | None = None, stacktrace:
Sequence[str] | None = None)
Bases: InvalidElementStateException
Thrown when an element is present on the DOM, but it is not visible, and so is not able to be interacted with.
Most commonly encountered when trying to click or read text of an element that is hidden from view.
exception selenium.common.exceptions.ImeActivationFailedException(msg: str | None = None,
screen: str | None = None,
stacktrace: Sequence[str] |
None = None)
Bases: WebDriverException
Thrown when activating an IME engine has failed.
exception selenium.common.exceptions.ImeNotAvailableException(msg: str | None = None, screen: str
| None = None, stacktrace:
Sequence[str] | None = None)
Bases: WebDriverException
Thrown when IME support is not available.
This exception is thrown for every IME-related method call if IME support is not available on the machine.
exception selenium.common.exceptions.InsecureCertificateException(msg: str | None = None,
screen: str | None = None,
stacktrace: Sequence[str] |
None = None)
Bases: WebDriverException
Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid
TLS certificate.
exception selenium.common.exceptions.InvalidArgumentException(msg: str | None = None, screen: str
| None = None, stacktrace:
Sequence[str] | None = None)
Bases: WebDriverException
The arguments passed to a command are either invalid or malformed.
7.1. Exceptions 33
Selenium Python Bindings, Release 2
7.1. Exceptions 35
Selenium Python Bindings, Release 2
__init__(msg: str | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None) →
None
print driver.window_handles
• Element may have been inside an iframe or another context which was refreshed.
__init__(msg: str | None = None, screen: str | None = None, stacktrace: Sequence[str] | None = None) →
None
7.1. Exceptions 37
Selenium Python Bindings, Release 2
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
Either way, the actions are performed in the order they are called, one after another.
__init__(driver: WebDriver, duration: int = 250, devices: list[AnyDevice] | None = None) → None
Creates a new ActionChains.
Args
• driver: The WebDriver instance which performs user actions.
• duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in Pointer-
Input
click(on_element: WebElement | None = None) → ActionChains
Clicks an element.
Args
• on_element: The element to click. If None, clicks on current mouse position.
click_and_hold(on_element: WebElement | None = None) → ActionChains
Holds down the left mouse button on an element.
Args
• on_element: The element to mouse down. If None, clicks on current mouse position.
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).
˓→perform()
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).
˓→perform()
Raises
If the origin with offset is outside the viewport. - MoveTargetOutOfBoundsException
- If the origin with offset is outside the viewport.
7.3 Alerts
Alert(driver).accept()
Alert(driver).dismiss()
name_prompt = Alert(driver)
name_prompt.send_keys("Willian Shakesphere")
name_prompt.accept()
alert_text = Alert(driver).text
self.assertEqual("Do you wish to quit?", alert_text)
__init__(driver) → None
Creates a new Alert.
Args
7.3. Alerts 41
Selenium Python Bindings, Release 2
dismiss() → None
Dismisses the alert available.
send_keys(keysToSend: str) → None
Send Keys to the Alert.
Args
• keysToSend: The text to be sent to Alert.
property text: str
Gets the text of the Alert.
ALT = '\ue00a'
ARROW_DOWN = '\ue015'
ARROW_LEFT = '\ue012'
ARROW_RIGHT = '\ue014'
ARROW_UP = '\ue013'
BACKSPACE = '\ue003'
BACK_SPACE = '\ue003'
CANCEL = '\ue001'
CLEAR = '\ue005'
COMMAND = '\ue03d'
CONTROL = '\ue009'
DECIMAL = '\ue028'
DELETE = '\ue017'
DIVIDE = '\ue029'
DOWN = '\ue015'
END = '\ue010'
ENTER = '\ue007'
EQUALS = '\ue019'
ESCAPE = '\ue00c'
F1 = '\ue031'
F10 = '\ue03a'
F11 = '\ue03b'
F12 = '\ue03c'
F2 = '\ue032'
F3 = '\ue033'
F4 = '\ue034'
F5 = '\ue035'
F6 = '\ue036'
F7 = '\ue037'
F8 = '\ue038'
F9 = '\ue039'
HELP = '\ue002'
HOME = '\ue011'
INSERT = '\ue016'
LEFT = '\ue012'
LEFT_ALT = '\ue00a'
LEFT_CONTROL = '\ue009'
LEFT_SHIFT = '\ue008'
META = '\ue03d'
MULTIPLY = '\ue024'
NULL = '\ue000'
NUMPAD0 = '\ue01a'
NUMPAD1 = '\ue01b'
NUMPAD2 = '\ue01c'
NUMPAD3 = '\ue01d'
NUMPAD4 = '\ue01e'
NUMPAD5 = '\ue01f'
NUMPAD6 = '\ue020'
NUMPAD7 = '\ue021'
NUMPAD8 = '\ue022'
NUMPAD9 = '\ue023'
PAGE_DOWN = '\ue00f'
PAGE_UP = '\ue00e'
PAUSE = '\ue00b'
RETURN = '\ue006'
RIGHT = '\ue014'
SEMICOLON = '\ue018'
SEPARATOR = '\ue026'
SHIFT = '\ue008'
SPACE = '\ue00d'
SUBTRACT = '\ue027'
TAB = '\ue004'
UP = '\ue013'
ZENKAKU_HANKAKU = '\ue040'
These are the attributes which can be used to locate elements. See the Locating Elements chapter for example usages.
The By implementation.
class selenium.webdriver.common.by.By
Bases: object
Set of supported locator strategies.
CLASS_NAME = 'class name'
ID = 'id'
NAME = 'name'
XPATH = 'xpath'
See the Using Selenium with remote WebDriver section for example usages of desired capabilities. The Desired
Capabilities implementation.
class selenium.webdriver.common.desired_capabilities.DesiredCapabilities
Bases: object
Set of default supported desired capabilities.
Use this as a starting point for creating a desired capabilities object for requesting remote webdrivers for con-
necting to selenium server or selenium grid.
Usage Example:
selenium_grid_url = "http://198.0.0.1:4444/wd/hub"
Note: Always use ‘.copy()’ on the DesiredCapabilities object to avoid the side effects of altering the Global class
instance.
CHROME = {'browserName': 'chrome'}
7.7 Proxy
auto_detect
Gets and Sets auto_detect
7.7.1 Usage
• Get
– self.auto_detect
• Set
– self.auto_detect = value
7.7.2 Parameters
value: str
autodetect = False
ftpProxy = ''
ftp_proxy
Gets and Sets ftp_proxy
7.7.3 Usage
• Get
– self.ftp_proxy
• Set
– self.ftp_proxy = value
7.7.4 Parameters
value: str
httpProxy = ''
http_proxy
Gets and Sets http_proxy
7.7.5 Usage
• Get
– self.http_proxy
• Set
– self.http_proxy = value
7.7.6 Parameters
value: str
noProxy = ''
no_proxy
Gets and Sets no_proxy
7.7.7 Usage
• Get
– self.no_proxy
• Set
– self.no_proxy = value
7.7. Proxy 47
Selenium Python Bindings, Release 2
7.7.8 Parameters
value: str
proxyAutoconfigUrl = ''
proxy_autoconfig_url
Gets and Sets proxy_autoconfig_url
7.7.9 Usage
• Get
– self.proxy_autoconfig_url
• Set
– self.proxy_autoconfig_url = value
7.7.10 Parameter
value: str
property proxy_type
Returns proxy type as ProxyType.
socksPassword = ''
socksProxy = ''
socksUsername = ''
socksVersion = None
socks_password
Gets and Sets socks_password
7.7.11 Usage
• Get
– self.socks_password
• Set
– self.socks_password = value
7.7.12 Parameter
value: str
socks_proxy
Gets and Sets socks_proxy
7.7.13 Usage
• Get
– self.sock_proxy
• Set
– self.socks_proxy = value
7.7.14 Parameter
value: str
socks_username
Gets and Sets socks_password
7.7.15 Usage
• Get
– self.socks_password
• Set
– self.socks_password = value
7.7.16 Parameter
value: str
socks_version
Gets and Sets socks_version
7.7.17 Usage
• Get
– self.socks_version
• Set
– self.socks_version = value
7.7. Proxy 49
Selenium Python Bindings, Release 2
7.7.18 Parameter
value: str
sslProxy = ''
ssl_proxy
Gets and Sets ssl_proxy
7.7.19 Usage
• Get
– self.ssl_proxy
• Set
– self.ssl_proxy = value
7.7.20 Parameter
value: str
class selenium.webdriver.common.proxy.ProxyType
Bases: object
Set of possible types of proxy.
Each proxy type has 2 properties: ‘ff_value’ is value of Firefox profile preference, ‘string’ is id of proxy type.
classmethod load(value)
class selenium.webdriver.common.proxy.ProxyTypeFactory
Bases: object
Factory for proxy types.
static make(ff_value, string)
7.8 Utilities
7.8. Utilities 51
Selenium Python Bindings, Release 2
7.9 Service
assert_process_still_running() → None
Check if the underlying process is still running.
abstract command_line_args() → List[str]
A List of program arguments (excluding the executable).
is_connectable() → bool
Establishes a socket connection to determine if the service running on the port is accessible.
send_remote_shutdown_command() → None
Dispatch an HTTP request to the shutdown endpoint for the service in an attempt to stop it.
start() → None
Starts the Service.
Exceptions
• WebDriverException : Raised either when it can’t start the service or when it can’t connect
to the service
stop() → None
Stops the service.
property path: str
with selenium.context(selenium.CONTEXT_CHROME):
# chrome scope
... do stuff ...
get_full_page_screenshot_as_base64() → str
Gets the full document screenshot of the current window as a base64 encoded string which is useful in
embedded images in HTML.
Usage
driver.get_full_page_screenshot_as_base64()
get_full_page_screenshot_as_file(filename) → bool
Saves a full document screenshot of the current window to a PNG image file. Returns False if there is any
IOError, else returns True. Use full paths in your filename.
Args
• filename: The full path you wish to save your screenshot to. This should end with a .png
extension.
Usage
driver.get_full_page_screenshot_as_file('/Screenshots/foo.png')
get_full_page_screenshot_as_png() → bytes
Gets the full document screenshot of the current window as a binary data.
Usage
driver.get_full_page_screenshot_as_png()
driver.install_addon('/path/to/firebug.xpi')
quit() → None
Closes the browser and shuts down the GeckoDriver executable.
save_full_page_screenshot(filename) → bool
Saves a full document screenshot of the current window to a PNG image file. Returns False if there is any
IOError, else returns True. Use full paths in your filename.
Args
• filename: The full path you wish to save your screenshot to. This should end with a .png
extension.
Usage
driver.save_full_page_screenshot('/Screenshots/foo.png')
set_context(context) → None
uninstall_addon(identifier) → None
Uninstalls Firefox addon using its identifier.
Usage
driver.uninstall_addon('[email protected]')
CONTEXT_CHROME = 'chrome'
CONTEXT_CONTENT = 'content'
class selenium.webdriver.firefox.options.Log
Bases: object
__init__() → None
to_capabilities() → dict
class selenium.webdriver.firefox.options.Options
Bases: ArgOptions
__init__() → None
Returns
The location of the binary.
property default_capabilities: dict
Return minimal capabilities necessary as a dictionary.
property preferences: dict
Returns
A dict of preferences.
property profile: FirefoxProfile
Returns
The Firefox profile to use.
exception selenium.webdriver.firefox.firefox_profile.AddonFormatError(**kwargs)
Bases: Exception
Exception for not well-formed add-on manifest files.
class selenium.webdriver.firefox.firefox_profile.FirefoxProfile(profile_directory=None)
Bases: object
__init__(profile_directory=None)
Initialises a new instance of a Firefox Profile.
Args
• profile_directory: Directory of profile that you want to use. If a directory is passed in it
will be cloned and the cloned directory will be used by the driver when instantiated. This
defaults to None and will create a new directory when object is created.
add_extension(extension=None)
set_preference(key, value)
Sets the preference that we want in the profile.
update_preferences()
Writes the desired user prefs to disk.
DEFAULT_PREFERENCES = None
property accept_untrusted_certs
property assume_untrusted_cert_issuer
class selenium.webdriver.firefox.firefox_binary.FirefoxBinary(**kwargs)
Bases: object
__init__(firefox_path=None, log_file=None)
Creates a new instance of Firefox binary.
Args
• firefox_path - Path to the Firefox executable. By default, it will be detected from the stan-
dard locations.
• log_file - A file object to redirect the firefox process output to. It can be sys.stdout.
Please note that with parallel run the output won’t be synchronous. By default, it will be
redirected to /dev/null.
add_command_line_options(*args)
kill()
Kill the browser.
This is useful when the browser is stuck.
launch_browser(profile, timeout=30)
Launches the browser for the given profile name.
It is assumed the profile already exists.
which(fname)
Returns the fully qualified path by searching Path of the given name.
NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'
class selenium.webdriver.chrome.options.Options
Bases: ChromiumOptions
enable_mobile(android_package: str = 'com.android.chrome', android_activity: str | None = None,
device_serial: str | None = None) → None
Enables mobile browser use for browsers that support it.
Args
android_activity: The name of the android package to start
driver.back()
bidi_connection()
close() → None
Closes the current window.
Usage
driver.close()
driver.delete_all_cookies()
delete_cookie(name) → None
Deletes a single cookie with the given name.
Usage
driver.delete_cookie('my_cookie')
delete_downloadable_files() → None
Deletes all downloadable files.
download_file(file_name: str, target_directory: str) → None
Downloads a file with the specified file name to the target directory.
file_name: The name of the file to download. target_directory: The path to the directory to save the down-
loaded file.
execute(driver_command: str, params: dict | None = None) → dict
Sends a command to be executed by a command.CommandExecutor.
Args
• driver_command: The name of the command to execute as a string.
• params: A dictionary of named parameters to send with the command.
Returns
The command’s JSON response loaded into a dictionary object.
execute_async_script(script: str, *args)
Asynchronously Executes JavaScript in the current window/frame.
Args
• script: The JavaScript to execute.
• *args: Any applicable arguments for your JavaScript.
Usage
execute_script(script, *args)
Synchronously Executes JavaScript in the current window/frame.
Args
• script: The JavaScript to execute.
• *args: Any applicable arguments for your JavaScript.
Usage
driver.execute_script('return document.title;')
with webdriver.file_detector_context(UselessFileDetector):
someinput.send_keys('/etc/hosts')
Args
• file_detector_class - Class of the desired file detector. If the class is different
from the current file_detector, then the class is instantiated with args and kwargs and
used as a file detector during the duration of the context manager.
• args - Optional arguments that get passed to the file detector class during
instantiation.
• kwargs - Keyword arguments, passed the same way as args.
Return type
WebElement
find_elements(by='id', value: str | None = None) → List[WebElement]
Find elements given a By strategy and locator.
Usage
Return type
list of WebElement
forward() → None
Goes one step forward in the browser history.
Usage
driver.forward()
fullscreen_window() → None
Invokes the window manager-specific ‘full screen’ operation.
get(url: str) → None
Loads a web page in the current browser session.
get_cookie(name) → Dict | None
Get a single cookie by name. Returns the cookie if found, None if not.
Usage
driver.get_cookie('my_cookie')
get_cookies() → List[dict]
Returns a set of dictionaries, corresponding to cookies visible in the current session.
Usage
driver.get_cookies()
get_credentials() → List[Credential]
Returns the list of credentials owned by the authenticator.
get_downloadable_files() → dict
Retrieves the downloadable files as a map of file names and their corresponding URLs.
get_log(log_type)
Gets the log for a given log type.
Args
• log_type: type of log that which will be returned
Usage
driver.get_log('browser')
driver.get_log('driver')
driver.get_log('client')
driver.get_log('server')
get_pinned_scripts() → List[str]
get_screenshot_as_base64() → str
Gets the screenshot of the current window as a base64 encoded string which is useful in embedded images
in HTML.
Usage
driver.get_screenshot_as_base64()
get_screenshot_as_file(filename) → bool
Saves a screenshot of the current window to a PNG image file. Returns False if there is any IOError, else
returns True. Use full paths in your filename.
Args
• filename: The full path you wish to save your screenshot to. This should end with a .png
extension.
Usage
driver.get_screenshot_as_file('/Screenshots/foo.png')
get_screenshot_as_png() → bytes
Gets the screenshot of the current window as a binary data.
Usage
driver.get_screenshot_as_png()
get_window_position(windowHandle='current') → dict
Gets the x,y position of the current window.
Usage
driver.get_window_position()
get_window_rect() → dict
Gets the x, y coordinates of the window as well as height and width of the current window.
Usage
driver.get_window_rect()
driver.get_window_size()
driver.implicitly_wait(30)
maximize_window() → None
Maximizes the current window that webdriver is using.
minimize_window() → None
Invokes the window manager-specific ‘minimize’ operation.
pin_script(script: str, script_key=None) → ScriptKey
Store common javascript scripts to be executed later by a unique hashable ID.
print_page(print_options: PrintOptions | None = None) → str
Takes PDF of the current page.
The driver makes a best effort to return a PDF based on the provided parameters.
quit() → None
Quits the driver and closes every associated window.
Usage
driver.quit()
refresh() → None
Refreshes the current page.
Usage
driver.refresh()
remove_all_credentials() → None
Removes all credentials from the authenticator.
remove_credential(credential_id: str | bytearray) → None
Removes a credential from the authenticator.
remove_virtual_authenticator() → None
Removes a previously added virtual authenticator.
The authenticator is no longer valid after removal, so no methods may be called.
save_screenshot(filename) → bool
Saves a screenshot of the current window to a PNG image file. Returns False if there is any IOError, else
returns True. Use full paths in your filename.
Args
• filename: The full path you wish to save your screenshot to. This should end with a .png
extension.
Usage
driver.save_screenshot('/Screenshots/foo.png')
driver.set_page_load_timeout(30)
driver.set_script_timeout(30)
driver.set_window_position(0,0)
driver.set_window_rect(x=10, y=10)
driver.set_window_rect(width=100, height=200)
driver.set_window_rect(x=10, y=10, width=100, height=200)
driver.set_window_size(800,600)
start_client()
Called before starting a new session.
This method may be overridden to define custom startup behavior.
start_session(capabilities: dict) → None
Creates a new session with the desired capabilities.
Args
• capabilities - a capabilities dict to start the session with.
stop_client()
Called after executing a quit command.
This method may be overridden to define custom shutdown behavior.
driver.current_url
driver.current_window_handle
property log_types
Gets a list of the available log types. This only works with w3c compliant browsers.
Usage
driver.log_types
name = driver.name
property orientation
Gets the current orientation of the device.
Usage
orientation = driver.orientation
driver.page_source
Returns
• SwitchTo: an object containing all options to switch focus into
Usage
element = driver.switch_to.active_element
alert = driver.switch_to.alert
driver.switch_to.default_content()
driver.switch_to.frame('frame_name')
driver.switch_to.frame(1)
driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0])
driver.switch_to.parent_frame()
driver.switch_to.window('main')
driver.timeouts
Return type
Timeout
property title: str
Returns the title of the current page.
Usage
title = driver.title
driver.window_handles
selenium.webdriver.remote.webdriver.get_remote_connection(capabilities, command_executor,
keep_alive, ignore_local_proxy=False)
selenium.webdriver.remote.webdriver.import_cdp()
class selenium.webdriver.remote.webelement.BaseWebElement
Bases: object
Abstract Base Class for WebElement.
ABC’s will allow custom types to be registered as a WebElement to pass type checks.
clear() → None
Clears the text if it’s a text entry element.
click() → None
Clicks the element.
find_element(by='id', value=None) → WebElement
Find an element given a By strategy and locator.
Usage
Return type
WebElement
find_elements(by='id', value=None) → List[WebElement]
Find elements given a By strategy and locator.
Usage
Return type
list of WebElement
get_attribute(name) → str | None
Gets the given attribute or property of the element.
This method will first try to return the value of a property with the given name. If a property with that name
doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name,
None is returned.
Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other
non-None values are returned as strings. For attributes or properties which do not exist, None is returned.
To obtain the exact value of the attribute or property, use get_dom_attribute() or get_property()
methods respectively.
Args
• name - Name of the attribute/property to retrieve.
Example:
get_dom_attribute(name) → str
Gets the given attribute of the element. Unlike get_attribute(), this method only returns attributes
declared in the element’s HTML markup.
Args
• name - Name of the attribute to retrieve.
Usage
text_length = target_element.get_dom_attribute("class")
text_length = target_element.get_property("text_length")
is_displayed() → bool
Whether the element is visible to a user.
is_enabled() → bool
Returns whether the element is enabled.
is_selected() → bool
Returns whether the element is selected.
Can be used to check if a checkbox or radio button is selected.
screenshot(filename) → bool
Saves a screenshot of the current element to a PNG image file. Returns False if there is any IOError, else
returns True. Use full paths in your filename.
Args
• filename: The full path you wish to save your screenshot to. This should end with a .png
extension.
Usage
element.screenshot('/Screenshots/foo.png')
submit() → None
Submits a form.
value_of_css_property(property_name) → str
The value of a CSS property.
property accessible_name: str
Returns the ARIA Level of the current webelement.
property aria_role: str
Returns the ARIA role of the current web element.
property id: str
Internal ID used by selenium.
This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same
element, can be done using ==:
if element1 == element2:
print("These 2 are equal")
img_b64 = element.screenshot_as_base64
element_png = element.screenshot_as_png
class selenium.webdriver.remote.command.Command
Bases: object
Defines constants for the standard WebDriver commands.
While these constants have no meaning in and of themselves, they are used to marshal commands through a
service that implements WebDriver’s remote wire protocol:
https://w3c.github.io/webdriver/
ADD_COOKIE: str = 'addCookie'
class selenium.webdriver.remote.errorhandler.ErrorCode
Bases: object
Error codes defined in the WebDriver wire protocol.
ELEMENT_CLICK_INTERCEPTED = [64, 'element click intercepted']
SUCCESS = 0
class selenium.webdriver.remote.errorhandler.ErrorHandler
Bases: object
Handles errors returned by the WebDriver server.
check_response(response: Dict[str, Any]) → None
Checks that a JSON response from the WebDriver does not have an error.
Args
• response - The JSON response from the WebDriver server as a dictionary object.
Raises
If the response contains an error message.
class selenium.webdriver.remote.errorhandler.ExceptionMapping
Bases: object
:Maps each errorcode in ErrorCode object to corresponding exception Please refer to https://www.w3.org/TR/
webdriver2/#errors for w3c specification
ELEMENT_CLICK_INTERCEPTED
alias of ElementClickInterceptedException
ELEMENT_IS_NOT_SELECTABLE
alias of ElementNotSelectableException
ELEMENT_NOT_INTERACTABLE
alias of ElementNotInteractableException
ELEMENT_NOT_VISIBLE
alias of ElementNotVisibleException
IME_ENGINE_ACTIVATION_FAILED
alias of ImeActivationFailedException
IME_NOT_AVAILABLE
alias of ImeNotAvailableException
INSECURE_CERTIFICATE
alias of InsecureCertificateException
INVALID_ARGUMENT
alias of InvalidArgumentException
INVALID_COOKIE_DOMAIN
alias of InvalidCookieDomainException
INVALID_COORDINATES
alias of InvalidCoordinatesException
INVALID_ELEMENT_STATE
alias of InvalidElementStateException
INVALID_SELECTOR
alias of InvalidSelectorException
INVALID_SESSION_ID
alias of InvalidSessionIdException
INVALID_XPATH_SELECTOR
alias of InvalidSelectorException
INVALID_XPATH_SELECTOR_RETURN_TYPER
alias of InvalidSelectorException
JAVASCRIPT_ERROR
alias of JavascriptException
MOVE_TARGET_OUT_OF_BOUNDS
alias of MoveTargetOutOfBoundsException
NO_ALERT_OPEN
alias of NoAlertPresentException
NO_SUCH_COOKIE
alias of NoSuchCookieException
NO_SUCH_ELEMENT
alias of NoSuchElementException
NO_SUCH_FRAME
alias of NoSuchFrameException
NO_SUCH_SHADOW_ROOT
alias of NoSuchShadowRootException
NO_SUCH_WINDOW
alias of NoSuchWindowException
SCRIPT_TIMEOUT
alias of TimeoutException
SESSION_NOT_CREATED
alias of SessionNotCreatedException
STALE_ELEMENT_REFERENCE
alias of StaleElementReferenceException
TIMEOUT
alias of TimeoutException
UNABLE_TO_CAPTURE_SCREEN
alias of ScreenshotException
UNABLE_TO_SET_COOKIE
alias of UnableToSetCookieException
UNEXPECTED_ALERT_OPEN
alias of UnexpectedAlertPresentException
UNKNOWN_ERROR
alias of WebDriverException
UNKNOWN_METHOD
alias of UnknownMethodException
class selenium.webdriver.remote.mobile.Mobile(driver)
Bases: object
ConnectionType
alias of _ConnectionType
__init__(driver)
set_network_connection(network)
Set the network connection for the remote device.
Example of setting airplane mode:
driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)
property context
Returns the current context (Native or WebView).
property contexts
Returns a list of available contexts.
property network_connection
close()
Clean up resources when finished with the remote_connection.
execute(command, params)
Send a command to the remote server.
Any path substitutions required for the URL mapped to the command should be included in the command
parameters.
Args
• command - A string specifying the command to execute.
• params - A dictionary of named parameters to send with the command as its JSON payload.
classmethod get_certificate_bundle_path()
Returns
Paths of the .pem encoded certificate to verify connection to command executor. Defaults to certifi.where()
or REQUESTS_CA_BUNDLE env variable if set.
classmethod get_remote_connection_headers(parsed_url, keep_alive=False)
Get headers for remote request.
Args
• parsed_url - The parsed url
• keep_alive (Boolean) - Is this a keep-alive connection (default: False)
classmethod get_timeout()
Returns
Timeout value in seconds for all http requests made to the Remote Connection
classmethod reset_timeout()
Reset the http request timeout to socket._GLOBAL_DEFAULT_TIMEOUT.
classmethod set_certificate_bundle_path(path)
Set the path to the certificate bundle to verify connection to command executor. Can also be set to None to
disable certificate validation.
Args
• path - path of a .pem encoded certificate chain.
classmethod set_timeout(timeout)
Override the default timeout.
Args
• timeout - timeout value for http requests in seconds
browser_name = None
get_permission(permission)
quit()
Closes the browser and shuts down the SafariDriver executable.
set_permission(permission, value)
command_line_args() → List[str]
A List of program arguments (excluding the executable).
property reuse_service: bool
Example:
from selenium.webdriver.support.ui import Select
Select(driver.find_element(By.TAG_NAME, “select”)).select_by_index(2)
deselect_all() → None
Clear all selected entries.
This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the
SELECT does not support multiple selections
deselect_by_index(index: int) → None
Deselect the option at the given index. This is done by examining the “index” attribute of an element, and
not merely by counting.
Args
• index - The option at this index will be deselected
throws NoSuchElementException If there is no option with specified index in SELECT
deselect_by_value(value: str) → None
Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect
an option like:
<option value=”foo”>Bar</option>
Args
• value - The value to match against
throws NoSuchElementException If there is no option with specified value in SELECT
Args
• text - The visible text to match against
throws NoSuchElementException If there is no option with specified text in SELECT
Raises
selenium.common.exceptions.TimeoutException if timeout occurs
print(Color.from_string('#00ff33').rgba)
print(Color.from_string('rgb(1, 255, 3)').hex)
print(Color.from_string('blue').rgba)
class selenium.webdriver.support.event_firing_webdriver.EventFiringWebDriver(driver:
WebDriver,
event_listener:
Ab-
stractEventLis-
tener)
Bases: object
A wrapper around an arbitrary WebDriver instance which supports firing events.
__init__(driver: WebDriver, event_listener: AbstractEventListener) → None
Creates a new instance of the EventFiringWebDriver.
Args
• driver : A WebDriver instance
• event_listener : Instance of a class that subclasses AbstractEventListener and implements
it fully or partially
Example:
class MyListener(AbstractEventListener):
def before_navigate_to(self, url, driver):
print("Before navigate to %s" % url)
def after_navigate_to(self, url, driver):
print("After navigate to %s" % url)
driver = Firefox()
ef_driver = EventFiringWebDriver(driver, MyListener())
ef_driver.get("http://www.google.co.in/")
back() → None
close() → None
execute_async_script(script, *args)
execute_script(script, *args)
forward() → None
quit() → None
click() → None
send_keys(*value) → None
class selenium.webdriver.support.abstract_event_listener.AbstractEventListener
Bases: object
Event listener must subclass and implement this fully or partially.
after_change_value_of(element, driver) → None
after_close(driver) → None
after_navigate_back(driver) → None
after_navigate_forward(driver) → None
after_quit(driver) → None
before_close(driver) → None
before_navigate_back(driver) → None
before_navigate_forward(driver) → None
before_quit(driver) → None
selenium.webdriver.support.expected_conditions.element_to_be_clickable(mark: WebElement |
Tuple[str, str]) →
Callable[[WebDriver |
WebElement],
Literal[False] |
WebElement]
An Expectation for checking an element is visible and enabled such that you can click it.
element is either a locator (text) or an WebElement
selenium.webdriver.support.expected_conditions.element_to_be_selected(element: WebElement)
→ Callable[[Any], bool]
An expectation for checking the selection is selected.
element is WebElement object
selenium.webdriver.support.expected_conditions.frame_to_be_available_and_switch_to_it(locator:
Tu-
ple[str,
str]
|
str)
→
Callable[[WebDriver],
bool]
An expectation for checking whether the given frame is available to switch to.
If the frame is available it switches the given driver to the specified frame.
selenium.webdriver.support.expected_conditions.invisibility_of_element(element: WebElement |
Tuple[str, str]) →
Callable[[WebDriver |
WebElement],
WebElement | bool]
An Expectation for checking that an element is either invisible or not present on the DOM.
element is either a locator (text) or an WebElement
selenium.webdriver.support.expected_conditions.invisibility_of_element_located(locator:
WebElement
| Tuple[str,
str]) →
Callable[[WebDriver
| WebEle-
ment],
WebElement |
bool]
An Expectation for checking that an element is either invisible or not present on the DOM.
locator used to find the element
selenium.webdriver.support.expected_conditions.new_window_is_opened(current_handles: List[str])
→ Callable[[WebDriver],
bool]
An expectation that a new window will be opened and have the number of windows handles increase.
selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_attribute(locator:
Tu-
ple[str,
str],
at-
tribute_:
str,
text_:
str)
→
Callable[[WebDriver
|
We-
bEle-
ment],
bool]
An expectation for checking if the given text is present in the element’s attribute.
locator, attribute, text
selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_value(locator:
Tu-
ple[str,
str],
text_:
str) →
Callable[[WebDriver
|
WebEle-
ment],
bool]
An expectation for checking if the given text is present in the element’s value.
locator, text
selenium.webdriver.support.expected_conditions.title_contains(title: str) → Callable[[WebDriver],
bool]
An expectation for checking that the title contains a case-sensitive substring.
title is the fragment of title expected returns True when the title matches, False otherwise
selenium.webdriver.support.expected_conditions.title_is(title: str) → Callable[[WebDriver], bool]
An expectation for checking the title of a page.
title is the expected title, which must be an exact match returns True if the title matches, false otherwise.
selenium.webdriver.support.expected_conditions.url_changes(url: str) → Callable[[WebDriver],
bool]
An expectation for checking the current url.
url is the expected url, which must not be an exact match returns True if the url is different, false otherwise.
selenium.webdriver.support.expected_conditions.url_contains(url: str) → Callable[[WebDriver],
bool]
An expectation for checking that the current url contains a case- sensitive substring.
url is the fragment of url expected, returns True when the url matches, False otherwise
EIGHT
Download the latest chromedriver from download page. Unzip the file:
unzip chromedriver_linux64.zip
You should see a chromedriver executable. Now you can create an instance of Chrome WebDriver like this:
driver = webdriver.Chrome(executable_path="/path/to/chromedriver")
Ref: http://seleniumhq.org/docs/03_webdriver.html#how-xpath-works-in-webdriver
Selenium delegates XPath queries down to the browser’s own XPath engine, so Selenium support XPath supports
whatever the browser supports. In browsers which don’t have native XPath engines (IE 6,7,8), Selenium supports
XPath 1.0 only.
Ref: http://blog.varunin.com/2011/08/scrolling-on-pages-using-selenium.html
You can use the execute_script method to execute javascript on the loaded page. So, you can call the JavaScript API
to scroll to the bottom or any other position of a page.
Here is an example to scroll to the bottom of a page:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
The window object in DOM has a scrollTo method to scroll to any position of an opened window. The scrollHeight
is a common property for all elements. The document.body.scrollHeight will give the height of the entire body of the
page.
93
Selenium Python Bindings, Release 2
Ref: http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox
Ref: http://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/
The first step is to identify the type of file you want to auto save.
To identify the content type you want to download automatically, you can use curl:
Another way to find content type is using the requests module, you can use it like this:
import requests
content_type = requests.head('http://www.python.org').headers['content-type']
print(content_type)
Once the content type is identified, you can use it to set the firefox profile preference: browser.helperApps.
neverAsk.saveToDisk
Here is an example:
import os
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
browser = webdriver.Firefox(firefox_profile=fp)
browser.get("http://pypi.python.org/pypi/selenium")
browser.find_element_by_partial_link_text("selenium-2").click()
Select the <input type="file"> element and call the send_keys() method passing the file path, either the path
relative to the test script, or an absolute path. Keep in mind the differences in path names between Windows and Unix
systems.
First download the Firebug XPI file, later you call the add_extension method available for the firefox profile:
fp = webdriver.FirefoxProfile()
fp.add_extension(extension='firebug-1.8.4.xpi')
fp.set_preference("extensions.firebug.currentVersion", "1.8.4") #Avoid startup screen
browser = webdriver.Firefox(firefox_profile=fp)
driver = webdriver.Firefox()
driver.get('http://www.python.org/')
driver.save_screenshot('screenshot.png')
driver.quit()
NINE
• genindex
• modindex
• search
97
Selenium Python Bindings, Release 2
s
selenium.common.exceptions, 32
selenium.webdriver.chrome.options, 57
selenium.webdriver.chrome.service, 58
selenium.webdriver.chrome.webdriver, 57
selenium.webdriver.common.action_chains, 38
selenium.webdriver.common.alert, 41
selenium.webdriver.common.by, 44
selenium.webdriver.common.desired_capabilities,
45
selenium.webdriver.common.keys, 42
selenium.webdriver.common.proxy, 46
selenium.webdriver.common.service, 52
selenium.webdriver.common.utils, 51
selenium.webdriver.firefox.firefox_binary, 56
selenium.webdriver.firefox.firefox_profile,
56
selenium.webdriver.firefox.options, 55
selenium.webdriver.firefox.webdriver, 53
selenium.webdriver.ie.webdriver, 79
selenium.webdriver.remote.command, 71
selenium.webdriver.remote.errorhandler, 74
selenium.webdriver.remote.mobile, 77
selenium.webdriver.remote.remote_connection,
78
selenium.webdriver.remote.utils, 79
selenium.webdriver.remote.webdriver, 58
selenium.webdriver.remote.webelement, 67
selenium.webdriver.safari.service, 80
selenium.webdriver.safari.webdriver, 80
selenium.webdriver.support.abstract_event_listener,
86
selenium.webdriver.support.color, 84
selenium.webdriver.support.event_firing_webdriver,
84
selenium.webdriver.support.expected_conditions,
86
selenium.webdriver.support.select, 81
selenium.webdriver.support.wait, 83
99
Selenium Python Bindings, Release 2
Symbols method), 59
__init__()
__init__() (selenium.common.exceptions.InvalidSelectorException (selenium.webdriver.remote.webelement.WebElement
method), 34 method), 68
__init__()
__init__() (selenium.common.exceptions.NoSuchDriverException (selenium.webdriver.safari.service.Service
method), 35 method), 80
__init__() (selenium.common.exceptions.NoSuchElementException (selenium.webdriver.safari.webdriver.WebDriver
__init__()
method), 35 method), 80
__init__() (selenium.common.exceptions.StaleElementReferenceException(selenium.webdriver.support.color.Color
__init__()
method), 37 method), 84
__init__() (selenium.webdriver.support.event_firing_webdriver.EventFiri
__init__() (selenium.common.exceptions.UnexpectedAlertPresentException
method), 37 method), 84
__init__()
__init__() (selenium.common.exceptions.WebDriverException (selenium.webdriver.support.event_firing_webdriver.EventFiri
method), 37 method), 85
__init__() (selenium.webdriver.chrome.service.Service __init__() (selenium.webdriver.support.select.Select
method), 58 method), 81
__init__()
__init__() (selenium.webdriver.chrome.webdriver.WebDriver (selenium.webdriver.support.wait.WebDriverWait
method), 57 method), 83
__init__() (selenium.webdriver.common.action_chains.ActionChains
method), 38 A
__init__() (selenium.webdriver.common.alert.Alert AbstractEventListener (class in sele-
method), 41 nium.webdriver.support.abstract_event_listener),
__init__() (selenium.webdriver.common.proxy.Proxy 86
method), 46 accept() (selenium.webdriver.common.alert.Alert
__init__() (selenium.webdriver.common.service.Service method), 42
method), 52 accept_untrusted_certs (sele-
__init__() (selenium.webdriver.firefox.firefox_binary.FirefoxBinary nium.webdriver.firefox.firefox_profile.FirefoxProfile
method), 56 property), 56
__init__() (selenium.webdriver.firefox.firefox_profile.FirefoxProfile
accessible_name (sele-
method), 56 nium.webdriver.remote.webelement.WebElement
__init__() (selenium.webdriver.firefox.options.Log property), 70
method), 55 ActionChains (class in sele-
__init__() (selenium.webdriver.firefox.options.Options nium.webdriver.common.action_chains),
method), 55 38
__init__() (selenium.webdriver.firefox.webdriver.WebDriver ADD (selenium.webdriver.common.keys.Keys attribute), 42
method), 53 add_command_line_options() (sele-
__init__() (selenium.webdriver.ie.webdriver.WebDriver nium.webdriver.firefox.firefox_binary.FirefoxBinary
method), 79 method), 57
__init__() (selenium.webdriver.remote.mobile.Mobile ADD_COOKIE (selenium.webdriver.remote.command.Command
method), 77 attribute), 71
add_cookie() (selenium.webdriver.remote.webdriver.WebDriver
__init__() (selenium.webdriver.remote.remote_connection.RemoteConnection
method), 78 method), 59
__init__() (selenium.webdriver.remote.webdriver.WebDriver ADD_CREDENTIAL (sele-
101
Selenium Python Bindings, Release 2
nium.webdriver.remote.command.Command nium.webdriver.support.expected_conditions),
attribute), 71 86
add_credential() (sele- aria_role (selenium.webdriver.remote.webelement.WebElement
nium.webdriver.remote.webdriver.WebDriver property), 70
method), 59 ARROW_DOWN (selenium.webdriver.common.keys.Keys at-
add_extension() (sele- tribute), 42
nium.webdriver.firefox.firefox_profile.FirefoxProfileARROW_LEFT (selenium.webdriver.common.keys.Keys at-
method), 56 tribute), 42
ADD_VIRTUAL_AUTHENTICATOR (sele- ARROW_RIGHT (selenium.webdriver.common.keys.Keys
nium.webdriver.remote.command.Command attribute), 42
attribute), 71 ARROW_UP (selenium.webdriver.common.keys.Keys
add_virtual_authenticator() (sele- attribute), 42
nium.webdriver.remote.webdriver.WebDriver assert_process_still_running() (sele-
method), 59 nium.webdriver.common.service.Service
AddonFormatError, 56 method), 52
after_change_value_of() (sele- assume_untrusted_cert_issuer (sele-
nium.webdriver.support.abstract_event_listener.AbstractEventListener
nium.webdriver.firefox.firefox_profile.FirefoxProfile
method), 86 property), 56
after_click() (selenium.webdriver.support.abstract_event_listener.AbstractEventListener
auto_detect (selenium.webdriver.common.proxy.Proxy
method), 86 attribute), 46
after_close() (selenium.webdriver.support.abstract_event_listener.AbstractEventListener
autodetect (selenium.webdriver.common.proxy.Proxy
method), 86 attribute), 46
after_execute_script() (sele- AUTODETECT (selenium.webdriver.common.proxy.ProxyType
nium.webdriver.support.abstract_event_listener.AbstractEventListener
attribute), 50
method), 86
B
after_find() (selenium.webdriver.support.abstract_event_listener.AbstractEventListener
method), 86 back() (selenium.webdriver.remote.webdriver.WebDriver
after_navigate_back() (sele- method), 59
nium.webdriver.support.abstract_event_listener.AbstractEventListener
back() (selenium.webdriver.support.event_firing_webdriver.EventFiringWe
method), 86 method), 85
after_navigate_forward() (sele- BACK_SPACE (selenium.webdriver.common.keys.Keys at-
nium.webdriver.support.abstract_event_listener.AbstractEventListener
tribute), 42
method), 86 BACKSPACE (selenium.webdriver.common.keys.Keys at-
after_navigate_to() (sele- tribute), 42
nium.webdriver.support.abstract_event_listener.AbstractEventListener
BaseWebDriver (class in sele-
method), 86 nium.webdriver.remote.webdriver), 58
after_quit() (selenium.webdriver.support.abstract_event_listener.AbstractEventListener
BaseWebElement (class in sele-
method), 86 nium.webdriver.remote.webelement), 67
AIRPLANE_MODE (selenium.webdriver.remote.mobile.Mobilebefore_change_value_of() (sele-
attribute), 77 nium.webdriver.support.abstract_event_listener.AbstractEventList
Alert (class in selenium.webdriver.common.alert), 41 method), 86
alert_is_present() (in module sele- before_click() (sele-
nium.webdriver.support.expected_conditions), nium.webdriver.support.abstract_event_listener.AbstractEventList
86 method), 86
ALL_NETWORK (selenium.webdriver.remote.mobile.Mobile before_close() (sele-
attribute), 77 nium.webdriver.support.abstract_event_listener.AbstractEventList
all_of() (in module sele- method), 86
nium.webdriver.support.expected_conditions), before_execute_script() (sele-
86 nium.webdriver.support.abstract_event_listener.AbstractEventList
all_selected_options (sele- method), 86
nium.webdriver.support.select.Select property), before_find() (selenium.webdriver.support.abstract_event_listener.Abstr
82 method), 86
ALT (selenium.webdriver.common.keys.Keys attribute), 42 before_navigate_back() (sele-
any_of() (in module sele- nium.webdriver.support.abstract_event_listener.AbstractEventList
102 Index
Selenium Python Bindings, Release 2
Index 103
Selenium Python Bindings, Release 2
property), 66 45
DIRECT (selenium.webdriver.common.proxy.ProxyType
D attribute), 50
DATA_NETWORK (selenium.webdriver.remote.mobile.Mobile dismiss() (selenium.webdriver.common.alert.Alert
attribute), 77 method), 42
debug() (selenium.webdriver.safari.webdriver.WebDriver DIVIDE (selenium.webdriver.common.keys.Keys at-
method), 80 tribute), 42
DECIMAL (selenium.webdriver.common.keys.Keys at- double_click() (sele-
tribute), 42 nium.webdriver.common.action_chains.ActionChains
default_capabilities (sele- method), 39
nium.webdriver.chrome.options.Options DOWN (selenium.webdriver.common.keys.Keys attribute),
property), 58 43
default_capabilities (sele- DOWNLOAD_FILE (selenium.webdriver.remote.command.Command
nium.webdriver.firefox.options.Options prop- attribute), 71
erty), 55 download_file() (sele-
DEFAULT_PREFERENCES (sele- nium.webdriver.remote.webdriver.WebDriver
nium.webdriver.firefox.firefox_profile.FirefoxProfile method), 60
attribute), 56 drag_and_drop() (sele-
DELETE (selenium.webdriver.common.keys.Keys at- nium.webdriver.common.action_chains.ActionChains
tribute), 42 method), 39
DELETE_ALL_COOKIES (sele- drag_and_drop_by_offset() (sele-
nium.webdriver.remote.command.Command nium.webdriver.common.action_chains.ActionChains
attribute), 71 method), 39
delete_all_cookies() (sele- dump_json() (in module sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.remote.utils), 79
method), 60
DELETE_COOKIE (selenium.webdriver.remote.command.Command E
attribute), 71 EDGE (selenium.webdriver.common.desired_capabilities.DesiredCapabilities
delete_cookie() (sele- attribute), 45
nium.webdriver.remote.webdriver.WebDriver element_attribute_to_include() (in module sele-
method), 60 nium.webdriver.support.expected_conditions),
DELETE_DOWNLOADABLE_FILES (sele- 87
nium.webdriver.remote.command.Command ELEMENT_CLICK_INTERCEPTED (sele-
attribute), 71 nium.webdriver.remote.errorhandler.ErrorCode
delete_downloadable_files() (sele- attribute), 74
nium.webdriver.remote.webdriver.WebDriver ELEMENT_CLICK_INTERCEPTED (sele-
method), 60 nium.webdriver.remote.errorhandler.ExceptionMapping
DELETE_SESSION (sele- attribute), 75
nium.webdriver.remote.command.Command ELEMENT_IS_NOT_SELECTABLE (sele-
attribute), 71 nium.webdriver.remote.errorhandler.ErrorCode
deselect_all() (sele- attribute), 74
nium.webdriver.support.select.Select method), ELEMENT_IS_NOT_SELECTABLE (sele-
81 nium.webdriver.remote.errorhandler.ExceptionMapping
deselect_by_index() (sele- attribute), 75
nium.webdriver.support.select.Select method), element_located_selection_state_to_be()
81 (in module sele-
deselect_by_value() (sele- nium.webdriver.support.expected_conditions),
nium.webdriver.support.select.Select method), 87
81 element_located_to_be_selected()
deselect_by_visible_text() (sele- (in module sele-
nium.webdriver.support.select.Select method), nium.webdriver.support.expected_conditions),
81 87
DesiredCapabilities (class in sele- ELEMENT_NOT_INTERACTABLE (sele-
nium.webdriver.common.desired_capabilities), nium.webdriver.remote.errorhandler.ErrorCode
104 Index
Selenium Python Bindings, Release 2
attribute), 74 method), 78
ELEMENT_NOT_INTERACTABLE (sele- execute() (selenium.webdriver.remote.webdriver.WebDriver
nium.webdriver.remote.errorhandler.ExceptionMapping method), 60
attribute), 75 EXECUTE_ASYNC_SCRIPT (sele-
ELEMENT_NOT_VISIBLE (sele- nium.webdriver.remote.command.Command
nium.webdriver.remote.errorhandler.ErrorCode attribute), 71
attribute), 74 execute_async_script() (sele-
ELEMENT_NOT_VISIBLE (sele- nium.webdriver.remote.webdriver.WebDriver
nium.webdriver.remote.errorhandler.ExceptionMapping method), 60
attribute), 76 execute_async_script() (sele-
ELEMENT_SCREENSHOT (sele- nium.webdriver.support.event_firing_webdriver.EventFiringWebD
nium.webdriver.remote.command.Command method), 85
attribute), 71 execute_script() (sele-
element_selection_state_to_be() (in module sele- nium.webdriver.remote.webdriver.WebDriver
nium.webdriver.support.expected_conditions), method), 60
87 execute_script() (sele-
element_to_be_clickable() (in module sele- nium.webdriver.support.event_firing_webdriver.EventFiringWebD
nium.webdriver.support.expected_conditions), method), 85
87
element_to_be_selected() (in module sele- F
nium.webdriver.support.expected_conditions), F1 (selenium.webdriver.common.keys.Keys attribute), 43
88 F10 (selenium.webdriver.common.keys.Keys attribute), 43
ElementClickInterceptedException, 32 F11 (selenium.webdriver.common.keys.Keys attribute), 43
ElementNotInteractableException, 32 F12 (selenium.webdriver.common.keys.Keys attribute), 43
ElementNotSelectableException, 33 F2 (selenium.webdriver.common.keys.Keys attribute), 43
ElementNotVisibleException, 33 F3 (selenium.webdriver.common.keys.Keys attribute), 43
enable_mobile() (sele- F4 (selenium.webdriver.common.keys.Keys attribute), 43
nium.webdriver.chrome.options.Options F5 (selenium.webdriver.common.keys.Keys attribute), 43
method), 57 F6 (selenium.webdriver.common.keys.Keys attribute), 43
enable_mobile() (sele- F7 (selenium.webdriver.common.keys.Keys attribute), 43
nium.webdriver.firefox.options.Options F8 (selenium.webdriver.common.keys.Keys attribute), 43
method), 55 F9 (selenium.webdriver.common.keys.Keys attribute), 43
encoded (selenium.webdriver.firefox.firefox_profile.FirefoxProfile
file_detector (selenium.webdriver.remote.webdriver.WebDriver
property), 56 property), 66
END (selenium.webdriver.common.keys.Keys attribute), 43 file_detector_context() (sele-
ENTER (selenium.webdriver.common.keys.Keys attribute), nium.webdriver.remote.webdriver.WebDriver
43 method), 61
EQUALS (selenium.webdriver.common.keys.Keys at- FIND_CHILD_ELEMENT (sele-
tribute), 43 nium.webdriver.remote.command.Command
ErrorCode (class in sele- attribute), 72
nium.webdriver.remote.errorhandler), 74 FIND_CHILD_ELEMENTS (sele-
ErrorHandler (class in sele- nium.webdriver.remote.command.Command
nium.webdriver.remote.errorhandler), 75 attribute), 72
ESCAPE (selenium.webdriver.common.keys.Keys at- find_connectable_ip() (in module sele-
tribute), 43 nium.webdriver.common.utils), 51
EventFiringWebDriver (class in sele- FIND_ELEMENT (selenium.webdriver.remote.command.Command
nium.webdriver.support.event_firing_webdriver), attribute), 72
84 find_element() (sele-
EventFiringWebElement (class in sele- nium.webdriver.remote.webdriver.WebDriver
nium.webdriver.support.event_firing_webdriver), method), 61
85 find_element() (sele-
ExceptionMapping (class in sele- nium.webdriver.remote.webelement.WebElement
nium.webdriver.remote.errorhandler), 75 method), 68
execute() (selenium.webdriver.remote.remote_connection.RemoteConnection
Index 105
Selenium Python Bindings, Release 2
106 Index
Selenium Python Bindings, Release 2
Index 107
Selenium Python Bindings, Release 2
108 Index
Selenium Python Bindings, Release 2
Index 109
Selenium Python Bindings, Release 2
selenium.webdriver.firefox.firefox_profile,NEW_WINDOW (selenium.webdriver.remote.command.Command
56 attribute), 73
selenium.webdriver.firefox.options, 55 new_window_is_opened() (in module sele-
selenium.webdriver.firefox.webdriver, 53 nium.webdriver.support.expected_conditions),
selenium.webdriver.ie.webdriver, 79 88
selenium.webdriver.remote.command, 71 NO_ALERT_OPEN (selenium.webdriver.remote.errorhandler.ErrorCode
selenium.webdriver.remote.errorhandler, attribute), 74
74 NO_ALERT_OPEN (selenium.webdriver.remote.errorhandler.ExceptionMappi
selenium.webdriver.remote.mobile, 77 attribute), 76
selenium.webdriver.remote.remote_connection, NO_FOCUS_LIBRARY_NAME (sele-
78 nium.webdriver.firefox.firefox_binary.FirefoxBinary
selenium.webdriver.remote.utils, 79 attribute), 57
selenium.webdriver.remote.webdriver, 58 no_proxy (selenium.webdriver.common.proxy.Proxy at-
selenium.webdriver.remote.webelement, 67 tribute), 47
selenium.webdriver.safari.service, 80 NO_SUCH_COOKIE (sele-
selenium.webdriver.safari.webdriver, 80 nium.webdriver.remote.errorhandler.ErrorCode
selenium.webdriver.support.abstract_event_listener, attribute), 74
86 NO_SUCH_COOKIE (sele-
selenium.webdriver.support.color, 84 nium.webdriver.remote.errorhandler.ExceptionMapping
selenium.webdriver.support.event_firing_webdriver,attribute), 76
84 NO_SUCH_ELEMENT (sele-
selenium.webdriver.support.expected_conditions, nium.webdriver.remote.errorhandler.ErrorCode
86 attribute), 75
selenium.webdriver.support.select, 81 NO_SUCH_ELEMENT (sele-
selenium.webdriver.support.wait, 83 nium.webdriver.remote.errorhandler.ExceptionMapping
move_by_offset() (sele- attribute), 76
nium.webdriver.common.action_chains.ActionChains
NO_SUCH_FRAME (selenium.webdriver.remote.errorhandler.ErrorCode
method), 39 attribute), 75
MOVE_TARGET_OUT_OF_BOUNDS (sele- NO_SUCH_FRAME (selenium.webdriver.remote.errorhandler.ExceptionMappi
nium.webdriver.remote.errorhandler.ErrorCode attribute), 76
attribute), 74 NO_SUCH_SHADOW_ROOT (sele-
MOVE_TARGET_OUT_OF_BOUNDS (sele- nium.webdriver.remote.errorhandler.ErrorCode
nium.webdriver.remote.errorhandler.ExceptionMapping attribute), 75
attribute), 76 NO_SUCH_SHADOW_ROOT (sele-
move_to_element() (sele- nium.webdriver.remote.errorhandler.ExceptionMapping
nium.webdriver.common.action_chains.ActionChains attribute), 76
method), 40 NO_SUCH_WINDOW (sele-
move_to_element_with_offset() (sele- nium.webdriver.remote.errorhandler.ErrorCode
nium.webdriver.common.action_chains.ActionChains attribute), 75
method), 40 NO_SUCH_WINDOW (sele-
MoveTargetOutOfBoundsException, 35 nium.webdriver.remote.errorhandler.ExceptionMapping
MULTIPLY (selenium.webdriver.common.keys.Keys attribute), 77
attribute), 43 NoAlertPresentException, 35
none_of() (in module sele-
N nium.webdriver.support.expected_conditions),
NAME (selenium.webdriver.common.by.By attribute), 44 88
name (selenium.webdriver.remote.webdriver.WebDriver noProxy (selenium.webdriver.common.proxy.Proxy at-
property), 66 tribute), 47
network_connection (sele- NoSuchAttributeException, 35
nium.webdriver.remote.mobile.Mobile prop- NoSuchCookieException, 35
erty), 78 NoSuchDriverException, 35
NEW_SESSION (selenium.webdriver.remote.command.Command NoSuchElementException, 35
attribute), 73 NoSuchFrameException, 36
NoSuchShadowRootException, 36
110 Index
Selenium Python Bindings, Release 2
Index 111
Selenium Python Bindings, Release 2
quit() (selenium.webdriver.safari.webdriver.WebDriver S
method), 80 SAFARI (selenium.webdriver.common.desired_capabilities.DesiredCapabili
quit() (selenium.webdriver.support.event_firing_webdriver.EventFiringWebDriver
attribute), 45
method), 85 save_full_page_screenshot() (sele-
nium.webdriver.firefox.webdriver.WebDriver
R method), 54
rect (selenium.webdriver.remote.webelement.WebElement save_screenshot() (sele-
property), 70 nium.webdriver.remote.webdriver.WebDriver
REFRESH (selenium.webdriver.remote.command.Command method), 64
attribute), 73 SCREENSHOT (selenium.webdriver.remote.command.Command
refresh() (selenium.webdriver.remote.webdriver.WebDriver attribute), 73
method), 64 screenshot() (selenium.webdriver.remote.webelement.WebElement
release() (selenium.webdriver.common.action_chains.ActionChainsmethod), 69
method), 40 screenshot_as_base64 (sele-
RemoteConnection (class in sele- nium.webdriver.remote.webelement.WebElement
nium.webdriver.remote.remote_connection), property), 70
78 screenshot_as_png (sele-
REMOVE_ALL_CREDENTIALS (sele- nium.webdriver.remote.webelement.WebElement
nium.webdriver.remote.command.Command property), 70
attribute), 73 ScreenshotException, 36
remove_all_credentials() (sele- SCRIPT_TIMEOUT (sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.remote.errorhandler.ErrorCode
method), 64 attribute), 75
REMOVE_CREDENTIAL (sele- SCRIPT_TIMEOUT (sele-
nium.webdriver.remote.command.Command nium.webdriver.remote.errorhandler.ExceptionMapping
attribute), 73 attribute), 77
remove_credential() (sele- scroll_by_amount() (sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.common.action_chains.ActionChains
method), 64 method), 40
REMOVE_VIRTUAL_AUTHENTICATOR (sele- scroll_from_origin() (sele-
nium.webdriver.remote.command.Command nium.webdriver.common.action_chains.ActionChains
attribute), 73 method), 40
remove_virtual_authenticator() (sele- scroll_to_element() (sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.common.action_chains.ActionChains
method), 64 method), 41
RESERVED_1 (selenium.webdriver.common.proxy.ProxyTypeSelect (class in selenium.webdriver.support.select), 81
attribute), 50 select_by_index() (sele-
reset_actions() (sele- nium.webdriver.support.select.Select method),
nium.webdriver.common.action_chains.ActionChains 82
method), 40 select_by_value() (sele-
reset_timeout() (sele- nium.webdriver.support.select.Select method),
nium.webdriver.remote.remote_connection.RemoteConnection
82
class method), 78 select_by_visible_text() (sele-
RETURN (selenium.webdriver.common.keys.Keys at- nium.webdriver.support.select.Select method),
tribute), 44 82
reuse_service (selenium.webdriver.safari.service.Service selenium.common.exceptions
property), 81 module, 32
rgb (selenium.webdriver.support.color.Color property), selenium.webdriver.chrome.options
84 module, 57
rgba (selenium.webdriver.support.color.Color property), selenium.webdriver.chrome.service
84 module, 58
RIGHT (selenium.webdriver.common.keys.Keys attribute), selenium.webdriver.chrome.webdriver
44 module, 57
selenium.webdriver.common.action_chains
112 Index
Selenium Python Bindings, Release 2
module, 38 module, 83
selenium.webdriver.common.alert SEMICOLON (selenium.webdriver.common.keys.Keys at-
module, 41 tribute), 44
selenium.webdriver.common.by send_keys() (selenium.webdriver.common.action_chains.ActionChains
module, 44 method), 41
selenium.webdriver.common.desired_capabilitiessend_keys() (selenium.webdriver.common.alert.Alert
module, 45 method), 42
selenium.webdriver.common.keys send_keys() (selenium.webdriver.remote.webelement.WebElement
module, 42 method), 69
selenium.webdriver.common.proxy send_keys() (selenium.webdriver.support.event_firing_webdriver.EventFir
module, 46 method), 85
selenium.webdriver.common.service SEND_KEYS_TO_ELEMENT (sele-
module, 52 nium.webdriver.remote.command.Command
selenium.webdriver.common.utils attribute), 73
module, 51 send_keys_to_element() (sele-
selenium.webdriver.firefox.firefox_binary nium.webdriver.common.action_chains.ActionChains
module, 56 method), 41
selenium.webdriver.firefox.firefox_profile send_remote_shutdown_command() (sele-
module, 56 nium.webdriver.common.service.Service
selenium.webdriver.firefox.options method), 52
module, 55 SEPARATOR (selenium.webdriver.common.keys.Keys at-
selenium.webdriver.firefox.webdriver tribute), 44
module, 53 Service (class in selenium.webdriver.chrome.service),
selenium.webdriver.ie.webdriver 58
module, 79 Service (class in selenium.webdriver.common.service),
selenium.webdriver.remote.command 52
module, 71 Service (class in selenium.webdriver.safari.service), 80
selenium.webdriver.remote.errorhandler service_url (selenium.webdriver.common.service.Service
module, 74 property), 52
selenium.webdriver.remote.mobile service_url (selenium.webdriver.safari.service.Service
module, 77 property), 81
selenium.webdriver.remote.remote_connection SESSION_NOT_CREATED (sele-
module, 78 nium.webdriver.remote.errorhandler.ErrorCode
selenium.webdriver.remote.utils attribute), 75
module, 79 SESSION_NOT_CREATED (sele-
selenium.webdriver.remote.webdriver nium.webdriver.remote.errorhandler.ExceptionMapping
module, 58 attribute), 77
selenium.webdriver.remote.webelement SessionNotCreatedException, 36
module, 67 set_certificate_bundle_path() (sele-
selenium.webdriver.safari.service nium.webdriver.remote.remote_connection.RemoteConnection
module, 80 class method), 79
selenium.webdriver.safari.webdriver set_context() (selenium.webdriver.firefox.webdriver.WebDriver
module, 80 method), 54
selenium.webdriver.support.abstract_event_listener
SET_NETWORK_CONNECTION (sele-
module, 86 nium.webdriver.remote.command.Command
selenium.webdriver.support.color attribute), 73
module, 84 set_network_connection() (sele-
selenium.webdriver.support.event_firing_webdriver nium.webdriver.remote.mobile.Mobile method),
module, 84 77
selenium.webdriver.support.expected_conditionsset_page_load_timeout() (sele-
module, 86 nium.webdriver.remote.webdriver.WebDriver
selenium.webdriver.support.select method), 64
module, 81 set_permission() (sele-
selenium.webdriver.support.wait nium.webdriver.safari.webdriver.WebDriver
Index 113
Selenium Python Bindings, Release 2
method), 80 attribute), 48
set_preference() (sele- socksUsername (selenium.webdriver.common.proxy.Proxy
nium.webdriver.firefox.firefox_profile.FirefoxProfile attribute), 48
method), 56 socksVersion (selenium.webdriver.common.proxy.Proxy
set_preference() (sele- attribute), 48
nium.webdriver.firefox.options.Options SPACE (selenium.webdriver.common.keys.Keys attribute),
method), 55 44
SET_SCREEN_ORIENTATION (sele- ssl_proxy (selenium.webdriver.common.proxy.Proxy at-
nium.webdriver.remote.command.Command tribute), 50
attribute), 73 sslProxy (selenium.webdriver.common.proxy.Proxy at-
set_script_timeout() (sele- tribute), 50
nium.webdriver.remote.webdriver.WebDriver STALE_ELEMENT_REFERENCE (sele-
method), 64 nium.webdriver.remote.errorhandler.ErrorCode
set_timeout() (selenium.webdriver.remote.remote_connection.RemoteConnection
attribute), 75
class method), 79 STALE_ELEMENT_REFERENCE (sele-
SET_TIMEOUTS (selenium.webdriver.remote.command.Command nium.webdriver.remote.errorhandler.ExceptionMapping
attribute), 73 attribute), 77
SET_USER_VERIFIED (sele- StaleElementReferenceException, 36
nium.webdriver.remote.command.Command staleness_of() (in module sele-
attribute), 73 nium.webdriver.support.expected_conditions),
set_user_verified() (sele- 89
nium.webdriver.remote.webdriver.WebDriver start() (selenium.webdriver.common.service.Service
method), 65 method), 52
set_window_position() (sele- start_client() (sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.remote.webdriver.WebDriver
method), 65 method), 65
SET_WINDOW_RECT (sele- start_session() (sele-
nium.webdriver.remote.command.Command nium.webdriver.remote.webdriver.WebDriver
attribute), 73 method), 65
set_window_rect() (sele- stop() (selenium.webdriver.common.service.Service
nium.webdriver.remote.webdriver.WebDriver method), 52
method), 65 stop_client() (selenium.webdriver.remote.webdriver.WebDriver
set_window_size() (sele- method), 65
nium.webdriver.remote.webdriver.WebDriver submit() (selenium.webdriver.remote.webelement.WebElement
method), 65 method), 70
shadow_root (selenium.webdriver.remote.webelement.WebElement SUBTRACT (selenium.webdriver.common.keys.Keys
property), 70 attribute), 44
SHIFT (selenium.webdriver.common.keys.Keys attribute), SUCCESS (selenium.webdriver.remote.errorhandler.ErrorCode
44 attribute), 75
size (selenium.webdriver.remote.webelement.WebElement switch_to (selenium.webdriver.remote.webdriver.WebDriver
property), 71 property), 66
socks_password (sele- SWITCH_TO_CONTEXT (sele-
nium.webdriver.common.proxy.Proxy at- nium.webdriver.remote.command.Command
tribute), 48 attribute), 73
socks_proxy (selenium.webdriver.common.proxy.Proxy SWITCH_TO_FRAME (sele-
attribute), 49 nium.webdriver.remote.command.Command
socks_username (sele- attribute), 73
nium.webdriver.common.proxy.Proxy at- SWITCH_TO_PARENT_FRAME (sele-
tribute), 49 nium.webdriver.remote.command.Command
socks_version (selenium.webdriver.common.proxy.Proxy attribute), 73
attribute), 49 SWITCH_TO_WINDOW (sele-
socksPassword (selenium.webdriver.common.proxy.Proxy nium.webdriver.remote.command.Command
attribute), 48 attribute), 73
socksProxy (selenium.webdriver.common.proxy.Proxy SYSTEM (selenium.webdriver.common.proxy.ProxyType
114 Index
Selenium Python Bindings, Release 2
attribute), 50 attribute), 77
UNABLE_TO_SET_COOKIE (sele-
T nium.webdriver.remote.errorhandler.ErrorCode
TAB (selenium.webdriver.common.keys.Keys attribute), 44 attribute), 75
TAG_NAME (selenium.webdriver.common.by.By attribute), UNABLE_TO_SET_COOKIE (sele-
45 nium.webdriver.remote.errorhandler.ExceptionMapping
tag_name (selenium.webdriver.remote.webelement.WebElement attribute), 77
property), 71 UnableToSetCookieException, 37
text (selenium.webdriver.common.alert.Alert property), UNEXPECTED_ALERT_OPEN (sele-
42 nium.webdriver.remote.errorhandler.ErrorCode
text (selenium.webdriver.remote.webelement.WebElement attribute), 75
property), 71 UNEXPECTED_ALERT_OPEN (sele-
text_to_be_present_in_element() (in module sele- nium.webdriver.remote.errorhandler.ExceptionMapping
nium.webdriver.support.expected_conditions), attribute), 77
89 UnexpectedAlertPresentException, 37
text_to_be_present_in_element_attribute() UnexpectedTagNameException, 37
(in module sele- uninstall_addon() (sele-
nium.webdriver.support.expected_conditions), nium.webdriver.firefox.webdriver.WebDriver
89 method), 54
text_to_be_present_in_element_value() UNKNOWN_COMMAND (sele-
(in module sele- nium.webdriver.remote.errorhandler.ErrorCode
nium.webdriver.support.expected_conditions), attribute), 75
90 UNKNOWN_ERROR (selenium.webdriver.remote.errorhandler.ErrorCode
TIMEOUT (selenium.webdriver.remote.errorhandler.ErrorCode attribute), 75
attribute), 75 UNKNOWN_ERROR (selenium.webdriver.remote.errorhandler.ExceptionMappi
TIMEOUT (selenium.webdriver.remote.errorhandler.ExceptionMappingattribute), 77
attribute), 77 UNKNOWN_METHOD (sele-
TimeoutException, 37 nium.webdriver.remote.errorhandler.ErrorCode
timeouts (selenium.webdriver.remote.webdriver.WebDriver attribute), 75
property), 67 UNKNOWN_METHOD (sele-
title (selenium.webdriver.remote.webdriver.WebDriver nium.webdriver.remote.errorhandler.ExceptionMapping
property), 67 attribute), 77
title_contains() (in module sele- UnknownMethodException, 37
nium.webdriver.support.expected_conditions), unpin() (selenium.webdriver.remote.webdriver.WebDriver
90 method), 65
title_is() (in module sele- UNSPECIFIED (selenium.webdriver.common.proxy.ProxyType
nium.webdriver.support.expected_conditions), attribute), 50
90 until() (selenium.webdriver.support.wait.WebDriverWait
to_capabilities() (sele- method), 83
nium.webdriver.common.proxy.Proxy method), until_not() (selenium.webdriver.support.wait.WebDriverWait
46 method), 83
to_capabilities() (sele- UP (selenium.webdriver.common.keys.Keys attribute), 44
nium.webdriver.firefox.options.Log method), update_preferences() (sele-
55 nium.webdriver.firefox.firefox_profile.FirefoxProfile
to_capabilities() (sele- method), 56
nium.webdriver.firefox.options.Options UPLOAD_FILE (selenium.webdriver.remote.command.Command
method), 55 attribute), 73
url_changes() (in module sele-
U nium.webdriver.support.expected_conditions),
UNABLE_TO_CAPTURE_SCREEN (sele- 90
nium.webdriver.remote.errorhandler.ErrorCode url_contains() (in module sele-
attribute), 75 nium.webdriver.support.expected_conditions),
UNABLE_TO_CAPTURE_SCREEN (sele- 90
url_matches()
nium.webdriver.remote.errorhandler.ExceptionMapping (in module sele-
Index 115
Selenium Python Bindings, Release 2
nium.webdriver.support.expected_conditions), attribute), 74
90 W3C_GET_WINDOW_HANDLES (sele-
url_to_be() (in module sele- nium.webdriver.remote.command.Command
nium.webdriver.support.expected_conditions), attribute), 74
91 W3C_MAXIMIZE_WINDOW (sele-
nium.webdriver.remote.command.Command
V attribute), 74
value_of_css_property() (sele- W3C_SET_ALERT_VALUE (sele-
nium.webdriver.remote.webelement.WebElement nium.webdriver.remote.command.Command
method), 70 attribute), 74
virtual_authenticator_id (sele- WebDriver (class in sele-
nium.webdriver.remote.webdriver.WebDriver nium.webdriver.chrome.webdriver), 57
property), 67 WebDriver (class in sele-
visibility_of() (in module sele- nium.webdriver.firefox.webdriver), 53
nium.webdriver.support.expected_conditions), WebDriver (class in selenium.webdriver.ie.webdriver),
91 79
visibility_of_all_elements_located() WebDriver (class in sele-
(in module sele- nium.webdriver.remote.webdriver), 58
nium.webdriver.support.expected_conditions), WebDriver (class in sele-
91 nium.webdriver.safari.webdriver), 80
visibility_of_any_elements_located() WebDriverException, 37
(in module sele- WebDriverWait (class in sele-
nium.webdriver.support.expected_conditions), nium.webdriver.support.wait), 83
91 WebElement (class in sele-
visibility_of_element_located() (in module sele- nium.webdriver.remote.webelement), 67
nium.webdriver.support.expected_conditions), WEBKITGTK (selenium.webdriver.common.desired_capabilities.DesiredCapa
91 attribute), 46
which() (selenium.webdriver.firefox.firefox_binary.FirefoxBinary
W method), 57
W3C_ACCEPT_ALERT (sele- WIFI_NETWORK (selenium.webdriver.remote.mobile.Mobile
nium.webdriver.remote.command.Command attribute), 77
attribute), 73 window_handles (sele-
W3C_ACTIONS (selenium.webdriver.remote.command.Command nium.webdriver.remote.webdriver.WebDriver
attribute), 73 property), 67
W3C_CLEAR_ACTIONS (sele- WPEWEBKIT (selenium.webdriver.common.desired_capabilities.DesiredCapa
nium.webdriver.remote.command.Command attribute), 46
attribute), 73 wrapped_driver (sele-
W3C_DISMISS_ALERT (sele- nium.webdriver.support.event_firing_webdriver.EventFiringWebD
nium.webdriver.remote.command.Command property), 85
attribute), 73 wrapped_element (sele-
W3C_EXECUTE_SCRIPT (sele- nium.webdriver.support.event_firing_webdriver.EventFiringWebE
nium.webdriver.remote.command.Command property), 85
attribute), 73
W3C_EXECUTE_SCRIPT_ASYNC (sele- X
nium.webdriver.remote.command.Command XPATH (selenium.webdriver.common.by.By attribute), 45
attribute), 73 XPATH_LOOKUP_ERROR (sele-
W3C_GET_ACTIVE_ELEMENT (sele- nium.webdriver.remote.errorhandler.ErrorCode
nium.webdriver.remote.command.Command attribute), 75
attribute), 73
W3C_GET_ALERT_TEXT (sele- Z
nium.webdriver.remote.command.Command ZENKAKU_HANKAKU (sele-
attribute), 74 nium.webdriver.common.keys.Keys attribute),
W3C_GET_CURRENT_WINDOW_HANDLE (sele- 44
nium.webdriver.remote.command.Command
116 Index