Api
Api
7. WebDriver API
Note:
This is not an official documentation. Official API documentation is available here.
The API definitions in this chapter show the absolute location of classes. However, the recommended import style is as given
below:
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
The exception classes can be imported like this (Replace the TheNameOfTheExceptionClass with the actual class name given
below):
Some attributes are callable (or methods) and others are non-callable (properties). All the callable attributes are ending with round
brackets.
current_url
Usage:
driver.current_url
v: latest
Here is an example of a method:
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 1/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
close()
Usage:
driver.close()
7.1. Exceptions
Exceptions that may happen in all the webdriver code.
The Element Click command could not be completed because the element receiving the events is obscuring the element that
was requested clicked.
Thrown when an element is present in the DOM but interactions with that element will hit another element do to paint order
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.
This may happen when communicating with the firefox extension or the remote driver server.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 2/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
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.
Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate.
Thrown when attempting to add a cookie under a different domain than the current URL.
Thrown when a command could not be completed because the element is in an invalid state.
This can be caused by attempting to clear an element that isn’t both editable and resettable.
Thrown when the selector which is used to find an element does not return a WebElement. Currently this only happens when
the selector is an xpath expression and it is either syntactically invalid (i.e. it is not a xpath expression) or the expression does
not select WebElements (e.g. “count(//input)”).
Occurs if the given session id is not in the list of active sessions, meaning the session either does not exist or that it’s not
active.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 3/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Thrown when the target provided to the ActionsChains move() method is invalid, i.e. out of document.
This can be caused by calling an operation on the Alert() class when an alert is not yet on the screen.
You may want to check if the attribute exists in the particular browser you are testing against. Some browsers may have
different property names for the same property. (IE8’s .innerText vs. Firefox .textContent)
No cookie matching the given path name was found amongst the associated cookies of the current browsing context’s active
document.
If you encounter this exception, you may want to check the following:
Check your selector used in your find_by…
Element may not yet be on the screen at the time of the find operation, (webpage is still loading) see
selenium.webdriver.support.wait.WebDriverWait() for how to write a wait wrapper to wait for an element to appear.
To find the current set of active window handles, you can get a list of the active window handles in the following way:
print driver.window_handles
Stale means the element no longer appears on the DOM of the page.
Usually raised when when an expected modal is blocking webdriver form executing any more commands.
Thrown when a support class did not get an expected web element.
The requested command matched a known URL but did not match an method for that URL.
v: latest
7.2. Action Chains
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 5/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and
context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
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)
Creates a new ActionChains.
Args: on_element: The element to click. If None, clicks on current mouse position.
click_and_hold (on_element=None)
Holds down the left mouse button on an element.
Args: on_element: The element to mouse down. If None, clicks on current mouse position.
context_click (on_element=None)
Performs a context-click (right click) on an element.
Args: on_element: The element to context-click. If None, clicks on current mouse position.
double_click (on_element=None)
Double-clicks an element.
Args: on_element: The element to double-click. If None, clicks on current mouse position.
drag_and_drop (source, target)
Holds down the left mouse button on the source element, v: latest
then moves to the target element and releases the mouse button.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 6/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
Args: value: The modifier key to send. Values are defined in Keys class.
element: The element to send keys. If None, sends a key to current focused element.
Example, pressing ctrl+c:
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
pause (seconds)
Pause all inputs for the specified duration in seconds
perform ()
Performs all stored actions.
v: latest
release (on_element=None)
Releasing a held mouse button on an element.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 7/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Args: on_element: The element to mouse up. If None, releases on current mouse position.
reset_actions ()
Clears actions that are already stored locally and on the remote end
send_keys (*keys_to_send)
Sends keys to current focused element.
Args: keys_to_send: The keys to send. Modifier keys constants can be found in the ‘Keys’ class.
send_keys_to_element (element, *keys_to_send)
Sends keys to an element.
7.3. Alerts
The Alert implementation.
Use this class to interact with alert prompts. It contains methods for dismissing, accepting, inputting, and getting text from
alert prompts.
Alert(driver).accept()
Alert(driver).dismiss()
dismiss ()
Dismisses the alert available.
send_keys (keysToSend)
Send Keys to the Alert.
v: latest
Args: keysToSend: The text to be sent to Alert.
text
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 8/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
class selenium.webdriver.common.keys.Keys
Bases: object
ADD = u'\ue025'
ALT = u'\ue00a'
ARROW_DOWN = u'\ue015'
ARROW_LEFT = u'\ue012'
ARROW_RIGHT = u'\ue014'
ARROW_UP = u'\ue013'
BACKSPACE = u'\ue003'
BACK_SPACE = u'\ue003'
CANCEL = u'\ue001'
CLEAR = u'\ue005'
COMMAND = u'\ue03d'
CONTROL = u'\ue009'
DECIMAL = u'\ue028'
DELETE = u'\ue017'
DIVIDE = u'\ue029'
DOWN = u'\ue015'
END = u'\ue010'
ENTER = u'\ue007'
EQUALS = u'\ue019'
ESCAPE = u'\ue00c'
F1 = u'\ue031'
F10 = u'\ue03a'
F11 = u'\ue03b'
F12 = u'\ue03c'
F2 = u'\ue032'
F3 = u'\ue033'
F4 = u'\ue034'
F5 = u'\ue035'
F6 = u'\ue036' v: latest
F7 = u'\ue037'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 9/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
F8 = u'\ue038'
F9 = u'\ue039'
HELP = u'\ue002'
HOME = u'\ue011'
INSERT = u'\ue016'
LEFT = u'\ue012'
LEFT_ALT = u'\ue00a'
LEFT_CONTROL = u'\ue009'
LEFT_SHIFT = u'\ue008'
META = u'\ue03d'
MULTIPLY = u'\ue024'
NULL = u'\ue000'
NUMPAD0 = u'\ue01a'
NUMPAD1 = u'\ue01b'
NUMPAD2 = u'\ue01c'
NUMPAD3 = u'\ue01d'
NUMPAD4 = u'\ue01e'
NUMPAD5 = u'\ue01f'
NUMPAD6 = u'\ue020'
NUMPAD7 = u'\ue021'
NUMPAD8 = u'\ue022'
NUMPAD9 = u'\ue023'
PAGE_DOWN = u'\ue00f'
PAGE_UP = u'\ue00e'
PAUSE = u'\ue00b'
RETURN = u'\ue006'
RIGHT = u'\ue014'
SEMICOLON = u'\ue018'
SEPARATOR = u'\ue026'
SHIFT = u'\ue008'
SPACE = u'\ue00d'
SUBTRACT = u'\ue027'
TAB = u'\ue004'
UP = u'\ue013'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 10/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
The By implementation.
class selenium.webdriver.common.by.By
Bases: object
ID = 'id'
NAME = 'name'
XPATH = 'xpath'
class selenium.webdriver.common.desired_capabilities.DesiredCapabilities
Bases: object
Use this as a starting point for creating a desired capabilities object for requesting remote webdrivers for connecting 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.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 11/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Generate touch actions. Works like ActionChains; actions are stored in the TouchActions object and are fired with perform().
__init__ (driver)
Creates a new TouchActions object.
Args: driver: The WebDriver instance which performs user actions. It should be with touchscreen enabled.
double_tap (on_element)
Double taps on a given element.
long_press (on_element)
Long press on an element.
perform ()
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 12/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
tap (on_element)
Taps on a given element.
7.8. Proxy
The Proxy implementation.
Proxy contains information about proxy type and necessary proxy settings.
__init__ (raw=None)
Creates a new Proxy.
Args: raw: raw proxy data. If None, default class values are used.
add_to_capabilities (capabilities)
Adds proxy information as capability in specified capabilities.
autodetect = False
ftp_proxy
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 13/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
httpProxy = ''
http_proxy
Returns http proxy setting.
noProxy = ''
no_proxy
Returns noproxy setting.
proxyAutoconfigUrl = ''
proxy_autoconfig_url
Returns proxy autoconfig url setting.
proxy_type
Returns proxy type as ProxyType.
socksPassword = ''
socksProxy = ''
socksUsername = ''
socks_password
Returns socks proxy password setting.
socks_proxy
Returns socks proxy setting.
socks_username
Returns socks proxy username setting.
sslProxy = ''
ssl_proxy
Returns https proxy setting.
class selenium.webdriver.common.proxy.ProxyType
Set of possible types of proxy.
7.9. Utilities
The Utils methods.
We prefer IPv4 so that we don’t change behavior from previous IPv4-only implementations, and because some drivers (e.g.,
FirefoxDriver) do not support IPv6 connections.
If the optional port number is provided, only IPs that listen on the given port are considered.
selenium.webdriver.common.utils.free_port ()
Determines a free port using sockets.
selenium.webdriver.common.utils.is_url_connectable (port)
Tries to connect to the HTTP server at /status path and specified port to see if it responds successfully.
This is a minimal implementation intended to cope with IPv6 literals. For example, _join_host_port(‘::1’, 80) == ‘[::1]:80’.
selenium.webdriver.common.utils.keys_to_typing (value)
Processes the values that will be typed in the element.
7.10. Service
class selenium.webdriver.common.service.Service (executable, port=0, log_file=-3, env=None, start_error_message='')
Bases: object
assert_process_still_running () v: latest
command_line_args ()
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 15/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
is_connectable ()
send_remote_shutdown_command ()
start ()
Starts the Service.
Exceptions: WebDriverException : Raised either when it can’t start the service or when it can’t connect to the service
stop ()
Stops the service.
service_url
Gets the url of the Service
__init__ (driver)
Creates a new Aplication Cache.
DOWNLOADING = 3
IDLE = 1
OBSOLETE = 5
UNCACHED = 0
UPDATE_READY = 4
status
Returns a current status of application cache.
Based on the combination and specificity of the various keyword arguments, a capabilities dictionary will be constructed
that is passed to the remote end.
v: latest
The keyword arguments given to this constructor are helpers to more easily allow Firefox WebDriver sessions to be
customised with different options. They are mapped on to a capabilities dictionary that is passed on to the remote end.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 16/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
As some of the options, such as firefox_profile and options.profile are mutually exclusive, precedence is given from how
specific the setting is. capabilities is the least specific keyword argument, followed by options, followed by firefox_binary and
firefox_profile.
In practice this means that if firefox_profile and options.profile are both set, the selected profile instance will always come
from the most specific variable. In this case that would be firefox_profile. This will result in options.profile to be ignored
because it is considered a less specific setting than the top-level firefox_profile keyword argument. Similarily, if you had
specified a capabilities[“moz:firefoxOptions”][“profile”] Base64 string, this would rank below options.profile.
Parameters: firefox_profile – Instance of FirefoxProfile object or a string. If undefined, a fresh profile will be
created in a temporary location on the system.
firefox_binary – Instance of FirefoxBinary or full path to the Firefox binary. If undefined, the system
default Firefox installation will be used.
timeout – Time to wait for Firefox to launch when using the extension connection.
capabilities – Dictionary of desired capabilities.
proxy – The proxy settings to us when communicating with Firefox via the extension connection.
executable_path – Full path to override which geckodriver binary to use for Firefox 47.0.1 and greater,
which defaults to picking up the binary from the system path.
options – Instance of options.Options.
service_log_path – Where to log information from the driver.
firefox_options – Deprecated argument for options
service_args – List of args to pass to the driver service
desired_capabilities – alias of capabilities. In future versions of this library, this will replace ‘capabilities’.
This will make the signature consistent with RemoteWebDriver.
log_path – Deprecated argument for service_log_path
keep_alive – Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive.
context (**kwds)
Sets the context that Selenium commands are running in using a with statement. The state of the context on the server is
saved before entering the block, and restored upon exiting it.
Parameters: context – Context, may be one of the class properties CONTEXT_CHROME or CONTEXT_CONTENT.
Usage example:
with selenium.context(selenium.CONTEXT_CHROME):
# chrome scope
... do stuff ...
Returns identifier of installed addon. This identifier can later be used to uninstall addon.
quit ()
Quits the driver and close every associated window.
set_context (context)
uninstall_addon (identifier)
Uninstalls Firefox addon using its identifier.
v: latest
Usage: driver.uninstall_addon(‘[email protected]’)
CONTEXT_CHROME = 'chrome'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 17/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
CONTEXT_CONTENT = 'content'
NATIVE_EVENTS_ALLOWED = True
firefox_profile
__init__ ()
x.__init__(…) initializes x; see help(type(x)) for signature
to_capabilities ()
class selenium.webdriver.firefox.options.Options
Bases: object
__init__ ()
x.__init__(…) initializes x; see help(type(x)) for signature
add_argument (argument)
Add argument to be used for the browser process.
set_headless (headless=True)
Deprecated, options.headless = True
to_capabilities ()
Marshals the Firefox options to a moz:firefoxOptions object.
KEY = 'moz:firefoxOptions'
accept_insecure_certs
arguments
Returns a list of browser process arguments.
binary
Returns the FirefoxBinary instance
binary_location
Returns the location of the binary.
capabilities
headless
Returns whether or not the headless argument is set
preferences v: latest
Returns a dict of preferences.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 18/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
profile
Returns the Firefox profile to use.
proxy
returns Proxy if set otherwise None.
__init__ (profile_directory=None)
Initialises a new instance of a Firefox Profile
Args: profile_directory: Directory of profile that you want to use. This defaults to None and will create a new directory
when object is created.
add_extension (extension='webdriver.xpi')
set_proxy (proxy)
update_preferences ()
ANONYMOUS_PROFILE_NAME = 'WEBDRIVER_ANONYMOUS_PROFILE'
DEFAULT_PREFERENCES = None
accept_untrusted_certs
assume_untrusted_cert_issuer
encoded
A zipped, base64 encoded string of profile directory for use with remote WebDriver JSON wire protocol
native_events_enabled
path
Gets the profile directory that is currently being used
port
Gets the port that WebDriver is working on
Args: firefox_path - Path to the Firefox executable. By default, it will be detected from the standard locations.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 19/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
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.
which (fname)
Returns the fully qualified path by searching Path of the given name
NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'
connect ()
Connects to the extension and retrieves the session id.
classmethod connect_and_quit ()
Connects to an running browser and quit immediately.
classmethod is_connectable ()
Trys to connect to the extension but do not retrieve context.
quit (sessionId=None)
Controls the ChromeDriver and allows you to drive the browser. v: latest
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 20/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Starts the service and then creates new instance of chrome driver.
Args: executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
port - port you would like the service to run, if left as 0, a free port will be found.
options - this takes an instance of ChromeOptions
service_args - List of args to pass to the driver service
desired_capabilities - Dictionary object with non-browser specific capabilities only, such as “proxy” or
“loggingPref”.
service_log_path - Where to log information from the driver.
chrome_options - Deprecated argument for options
keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
create_options ()
The command and command args should follow chrome devtools protocol domains/commands, refer to link
https://chromedevtools.github.io/devtools-protocol/
Returns: A dict, empty dict {} if there is no result to return. For example to getResponseBody:
get_network_conditions ()
Gets Chrome network emulation settings.
launch_app (id)
Launches Chrome app specified by id.
quit ()
Closes the browser and shuts down the ChromeDriver executable that is started when starting the ChromeDriver
set_network_conditions (**network_conditions)
Sets Chrome network emulation settings.
Note: ‘throughput’ can be used to set both (for download and upload).
v: latest
class selenium.webdriver.chrome.options.Options
Bases: object
__init__ ()
x.__init__(…) initializes x; see help(type(x)) for signature
add_argument (argument)
Adds an argument to the list
add_encoded_extension (extension)
Adds Base64 encoded string with extension data to a list that will be used to extract it to the ChromeDriver
Args:
name: The experimental option name. value: The option value.
add_extension (extension)
Adds the path to the extension to a list that will be used to extract it to the ChromeDriver
set_headless (headless=True)
Deprecated, options.headless = True
to_capabilities ()
Creates a capabilities with all the options that have been set and
KEY = 'goog:chromeOptions'
arguments
Returns a list of arguments needed for the browser
binary_location
Returns the location of the binary otherwise an empty string
capabilities
debugger_address
Returns the address of the remote devtools instance
experimental_options
Returns a dictionary of experimental options for chrome.
extensions
Returns a list of encoded extensions that will be loaded into chrome
v: latest
headless
Returns whether or not the headless argument is set
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 22/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Controls a browser by sending commands to a remote server. This server is expected to be running the WebDriver wire
protocol as defined at https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
Attributes: session_id - String ID of the browser session started and controlled by this WebDriver.
capabilities - Dictionaty of effective capabilities of this browser session as returned
by the remote server. See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
command_executor - remote_connection.RemoteConnection object used to execute commands.
error_handler - errorhandler.ErrorHandler object used to handle errors.
Args: command_executor - Either a string representing URL of the remote server or a custom
remote_connection.RemoteConnection object. Defaults to ‘http://127.0.0.1:4444/wd/hub’.
desired_capabilities - A dictionary of capabilities to request when
starting the browser session. Required parameter.
browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object.
Only used if Firefox is requested. Optional.
proxy - A selenium.webdriver.common.proxy.Proxy object. The browser session will
be started with given proxy settings, if possible. Optional.
keep_alive - Whether to configure remote_connection.RemoteConnection to use
HTTP keep-alive. Defaults to False.
file_detector - Pass custom file detector object during instantiation. If None,
then default LocalFileDetector() will be used. v: latest
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 23/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
add_cookie (cookie_dict)
Adds a cookie to your current session.
Args: cookie_dict: A dictionary object, with required keys - “name” and “value”;
optional keys - “path”, “domain”, “secure”, “expiry”
Usage:
driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’}) driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’, ‘path’ : ‘/’})
driver.add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’, ‘path’ : ‘/’, ‘secure’:True})
back ()
Goes one step backward in the browser history.
Usage: driver.back()
close ()
Closes the current window.
Usage: driver.close()
create_web_element (element_id)
Creates a web element with the specified element_id.
delete_all_cookies ()
Delete all cookies in the scope of the session.
Usage: driver.delete_all_cookies()
delete_cookie (name)
Deletes a single cookie with the given name.
Usage: driver.delete_cookie(‘my_cookie’)
Example:
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.
find_element (by='id', value=None)
Find an element given a By strategy and locator. Prefer the find_element_by_* methods when possible.
find_element_by_css_selector (css_selector)
Finds an element by css selector.
find_element_by_id (id_)
Finds an element by id.
find_element_by_link_text (link_text)
Finds an element by link text.
find_element_by_name (name)
Finds an element by name.
v: latest
Args: name: The name of the element to find.
Returns: WebElement - the element if it was found
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 25/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
find_element_by_partial_link_text (link_text)
Finds an element by a partial match of its link text.
find_element_by_tag_name (name)
Finds an element by tag name.
find_element_by_xpath (xpath)
Finds an element by xpath.
find_elements_by_class_name (name)
Finds elements by class name.
find_elements_by_css_selector (css_selector)
Finds elements by css selector.
find_elements_by_id (id_)
Finds multiple elements by id.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 26/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
find_elements_by_link_text (text)
Finds elements by link text.
find_elements_by_name (name)
Finds elements by name.
find_elements_by_partial_link_text (link_text)
Finds elements by a partial match of their link text.
find_elements_by_tag_name (name)
Finds elements by tag name.
find_elements_by_xpath (xpath)
Finds multiple elements by xpath.
forward ()
Goes one step forward in the browser history.
Usage: driver.forward()
fullscreen_window ()
Invokes the window manager-specific ‘full screen’ operation
get (url)
Loads a web page in the current browser session.
get_cookie (name)
Get a single cookie by name. Returns the cookie if found, None if not.
Usage: driver.get_cookie(‘my_cookie’)
get_cookies ()
Returns a set of dictionaries, corresponding to cookies visible in the current session. v: latest
Usage: driver.get_cookies()
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 27/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
get_log (log_type)
Gets the log for a given log type
get_screenshot_as_base64 ()
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)
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 ()
Gets the screenshot of the current window as a binary data.
Usage: driver.get_screenshot_as_png()
get_window_position (windowHandle='current')
Gets the x,y position of the current window.
Usage: driver.get_window_position()
get_window_rect ()
Gets the x, y coordinates of the window as well as height and width of the current window.
Usage: driver.get_window_rect()
get_window_size (windowHandle='current')
Gets the width and height of the current window.
Usage: driver.get_window_size()
implicitly_wait (time_to_wait)
Sets a sticky timeout to implicitly wait for an element to be found,
or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to
execute_async_script, see set_script_timeout.
Args: time_to_wait: Amount of time to wait (in seconds)
Usage: driver.implicitly_wait(30)
maximize_window ()
Maximizes the current window that webdriver is using
minimize_window ()
Invokes the window manager-specific ‘minimize’ operation
quit ()
Quits the driver and closes every associated window.
v: latest
Usage: driver.quit()
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 28/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
refresh ()
Refreshes the current page.
Usage: driver.refresh()
save_screenshot (filename)
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’)
set_page_load_timeout (time_to_wait)
Set the amount of time to wait for a page load to complete
before throwing an error.
Args: time_to_wait: The amount of time to wait
Usage: driver.set_page_load_timeout(30)
set_script_timeout (time_to_wait)
Set the amount of time that the script should wait during an
execute_async_script call before throwing an error.
Args: time_to_wait: The amount of time to wait (in seconds)
Usage: driver.set_script_timeout(30)
start_client ()
Called before starting a new session. This method may be overridden to define custom startup behavior.
switch_to_active_element ()
Deprecated use driver.switch_to.active_element
switch_to_alert ()
Deprecated use driver.switch_to.alert
switch_to_default_content ()
Deprecated use driver.switch_to.default_content
switch_to_frame (frame_reference)
Deprecated use driver.switch_to.frame
switch_to_window (window_name)
Deprecated use driver.switch_to.window
application_cache
Returns a ApplicationCache Object to interact with the browser app cache
current_url
Gets the URL of the current page.
Usage: driver.current_url
current_window_handle
Returns the handle of the current window.
Usage: driver.current_window_handle
desired_capabilities
returns the drivers current desired capabilities being used
file_detector
log_types
Gets a list of the available log types
Usage: driver.log_types
mobile
name
Returns the name of the underlying browser for this instance.
Usage: driver.page_source
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 30/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
switch_to
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’)
title
Returns the title of the current page.
Usage: driver.window_handles
Generally, all interesting operations that interact with a document will be performed through this interface.
All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines
whether or not the element is still attached to the DOM. If this test fails, then an StaleElementReferenceException is
thrown, and all future calls to this instance will fail.
clear ()
Clears the text if it’s a text entry element.
click ()
Clicks the element.
find_element_by_class_name (name)
Finds element within this element’s children by class name.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 31/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
find_element_by_id (id_)
Finds element within this element’s children by ID.
find_element_by_link_text (link_text)
Finds element within this element’s children by visible link text.
find_element_by_name (name)
Finds element within this element’s children by name.
find_element_by_partial_link_text (link_text)
Finds element within this element’s children by partially visible link text.
find_element_by_tag_name (name)
Finds element within this element’s children by tag name.
find_element_by_xpath (xpath)
Finds element by xpath.
This will select the first link under this element. v: latest
myelement.find_element_by_xpath(".//a")
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 32/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
myelement.find_element_by_xpath("//a")
find_elements_by_css_selector (css_selector)
Finds a list of elements within this element’s children by CSS selector.
find_elements_by_id (id_)
Finds a list of elements within this element’s children by ID. Will return a list of webelements if found, or an empty list if
not.
find_elements_by_link_text (link_text)
Finds a list of elements within this element’s children by visible link text.
find_elements_by_name (name)
Finds a list of elements within this element’s children by name.
find_elements_by_partial_link_text (link_text)
Finds a list of elements within this element’s children by link text.
v: latest
Args: link_text: The text of the element to partial match on.
Returns: list of webelement - a list with elements if any was found. an empty list if not
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 33/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
find_elements_by_tag_name (name)
Finds a list of elements within this element’s children by tag name.
find_elements_by_xpath (xpath)
Finds elements within the element by xpath.
myelement.find_elements_by_xpath(".//a")
myelement.find_elements_by_xpath("//a")
Returns: list of WebElement - a list with elements if any was found. An empty list if not
Usage: elements = element.find_elements_by_xpath(“//div[contains(@class, ‘foo’)]”)
get_attribute (name)
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.
get_property (name)
Gets the given property of the element.
text_length = target_element.get_property("text_length")
is_displayed ()
Whether the element is visible to a user.
v: latest
is_enabled ()
Returns whether the element is enabled.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 34/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
is_selected ()
Returns whether the element is selected.
screenshot (filename)
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’)
send_keys (*value)
Simulates typing into the element.
Args: value - A string for typing, or setting form fields. For setting file inputs, this could be a local file path.
Use this to send simple key events or to fill out form fields:
form_textfield = driver.find_element_by_name('username')
form_textfield.send_keys("admin")
file_input = driver.find_element_by_name('profilePic')
file_input.send_keys("path/to/profilepic.gif")
# Generally it's better to wrap the file path in one of the methods
# in os.path to return the actual path to support cross OS testing.
# file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
submit ()
Submits a form.
value_of_css_property (property_name)
The value of a CSS property.
id
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")
location
The location of the element in the renderable canvas.
location_once_scrolled_into_view
THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so
that we can click it. This method should cause the element to be scrolled into view.
Returns the top lefthand corner location on the screen, or None if the element is not visible.
parent v: latest
Internal reference to the WebDriver instance this element was found from.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 35/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
rect
A dictionary with the size and location of the element.
screenshot_as_base64
Gets the screenshot of the current element as a base64 encoded string.
tag_name
This element’s tagName property.
text
The text of the element.
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://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
ACCEPT_ALERT = 'acceptAlert'
ADD_COOKIE = 'addCookie'
CLEAR_APP_CACHE = 'clearAppCache'
CLEAR_ELEMENT = 'clearElement'
CLEAR_LOCAL_STORAGE = 'clearLocalStorage'
CLEAR_SESSION_STORAGE = 'clearSessionStorage'
CLICK = 'mouseClick'
CLICK_ELEMENT = 'clickElement'
CLOSE = 'close'
CONTEXT_HANDLES = 'getContextHandles'
CURRENT_CONTEXT_HANDLE = 'getCurrentContextHandle'
DELETE_ALL_COOKIES = 'deleteAllCookies'
DELETE_COOKIE = 'deleteCookie'
DELETE_SESSION = 'deleteSession'
DOUBLE_CLICK = 'mouseDoubleClick'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 36/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
DOUBLE_TAP = 'touchDoubleTap'
ELEMENT_EQUALS = 'elementEquals'
ELEMENT_SCREENSHOT = 'elementScreenshot'
EXECUTE_ASYNC_SCRIPT = 'executeAsyncScript'
EXECUTE_SCRIPT = 'executeScript'
EXECUTE_SQL = 'executeSql'
FIND_CHILD_ELEMENT = 'findChildElement'
FIND_CHILD_ELEMENTS = 'findChildElements'
FIND_ELEMENT = 'findElement'
FIND_ELEMENTS = 'findElements'
FLICK = 'touchFlick'
FULLSCREEN_WINDOW = 'fullscreenWindow'
GET = 'get'
GET_ACTIVE_ELEMENT = 'getActiveElement'
GET_ALERT_TEXT = 'getAlertText'
GET_ALL_COOKIES = 'getCookies'
GET_ALL_SESSIONS = 'getAllSessions'
GET_APP_CACHE = 'getAppCache'
GET_APP_CACHE_STATUS = 'getAppCacheStatus'
GET_AVAILABLE_LOG_TYPES = 'getAvailableLogTypes'
GET_COOKIE = 'getCookie'
GET_CURRENT_URL = 'getCurrentUrl'
GET_CURRENT_WINDOW_HANDLE = 'getCurrentWindowHandle'
GET_ELEMENT_ATTRIBUTE = 'getElementAttribute'
GET_ELEMENT_LOCATION = 'getElementLocation'
GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW = 'getElementLocationOnceScrolledIntoView'
GET_ELEMENT_PROPERTY = 'getElementProperty'
GET_ELEMENT_RECT = 'getElementRect'
GET_ELEMENT_SIZE = 'getElementSize'
GET_ELEMENT_TAG_NAME = 'getElementTagName'
GET_ELEMENT_TEXT = 'getElementText'
GET_ELEMENT_VALUE = 'getElementValue'
GET_ELEMENT_VALUE_OF_CSS_PROPERTY = 'getElementValueOfCssProperty'
GET_LOCAL_STORAGE_ITEM = 'getLocalStorageItem'
GET_LOCAL_STORAGE_KEYS = 'getLocalStorageKeys'
GET_LOCAL_STORAGE_SIZE = 'getLocalStorageSize'
v: latest
GET_LOCATION = 'getLocation'
GET_LOG = 'getLog'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 37/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
GET_NETWORK_CONNECTION = 'getNetworkConnection'
GET_PAGE_SOURCE = 'getPageSource'
GET_SCREEN_ORIENTATION = 'getScreenOrientation'
GET_SESSION_STORAGE_ITEM = 'getSessionStorageItem'
GET_SESSION_STORAGE_KEYS = 'getSessionStorageKeys'
GET_SESSION_STORAGE_SIZE = 'getSessionStorageSize'
GET_TITLE = 'getTitle'
GET_WINDOW_HANDLES = 'getWindowHandles'
GET_WINDOW_POSITION = 'getWindowPosition'
GET_WINDOW_RECT = 'getWindowRect'
GET_WINDOW_SIZE = 'getWindowSize'
GO_BACK = 'goBack'
GO_FORWARD = 'goForward'
IMPLICIT_WAIT = 'implicitlyWait'
IS_ELEMENT_DISPLAYED = 'isElementDisplayed'
IS_ELEMENT_ENABLED = 'isElementEnabled'
IS_ELEMENT_SELECTED = 'isElementSelected'
LONG_PRESS = 'touchLongPress'
MAXIMIZE_WINDOW = 'windowMaximize'
MINIMIZE_WINDOW = 'minimizeWindow'
MOUSE_DOWN = 'mouseButtonDown'
MOUSE_UP = 'mouseButtonUp'
MOVE_TO = 'mouseMoveTo'
NEW_SESSION = 'newSession'
QUIT = 'quit'
REFRESH = 'refresh'
REMOVE_LOCAL_STORAGE_ITEM = 'removeLocalStorageItem'
REMOVE_SESSION_STORAGE_ITEM = 'removeSessionStorageItem'
SCREENSHOT = 'screenshot'
SEND_KEYS_TO_ACTIVE_ELEMENT = 'sendKeysToActiveElement'
SEND_KEYS_TO_ELEMENT = 'sendKeysToElement'
SET_ALERT_CREDENTIALS = 'setAlertCredentials'
SET_ALERT_VALUE = 'setAlertValue'
SET_ELEMENT_SELECTED = 'setElementSelected'
SET_LOCAL_STORAGE_ITEM = 'setLocalStorageItem'
SET_LOCATION = 'setLocation'
v: latest
SET_NETWORK_CONNECTION = 'setNetworkConnection'
SET_SCREEN_ORIENTATION = 'setScreenOrientation'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 38/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
SET_SCRIPT_TIMEOUT = 'setScriptTimeout'
SET_SESSION_STORAGE_ITEM = 'setSessionStorageItem'
SET_TIMEOUTS = 'setTimeouts'
SET_WINDOW_POSITION = 'setWindowPosition'
SET_WINDOW_RECT = 'setWindowRect'
SET_WINDOW_SIZE = 'setWindowSize'
SINGLE_TAP = 'touchSingleTap'
STATUS = 'status'
SUBMIT_ELEMENT = 'submitElement'
SWITCH_TO_CONTEXT = 'switchToContext'
SWITCH_TO_FRAME = 'switchToFrame'
SWITCH_TO_PARENT_FRAME = 'switchToParentFrame'
SWITCH_TO_WINDOW = 'switchToWindow'
TOUCH_DOWN = 'touchDown'
TOUCH_MOVE = 'touchMove'
TOUCH_SCROLL = 'touchScroll'
TOUCH_UP = 'touchUp'
UPLOAD_FILE = 'uploadFile'
W3C_ACCEPT_ALERT = 'w3cAcceptAlert'
W3C_ACTIONS = 'actions'
W3C_CLEAR_ACTIONS = 'clearActionState'
W3C_DISMISS_ALERT = 'w3cDismissAlert'
W3C_EXECUTE_SCRIPT = 'w3cExecuteScript'
W3C_EXECUTE_SCRIPT_ASYNC = 'w3cExecuteScriptAsync'
W3C_GET_ACTIVE_ELEMENT = 'w3cGetActiveElement'
W3C_GET_ALERT_TEXT = 'w3cGetAlertText'
W3C_GET_CURRENT_WINDOW_HANDLE = 'w3cGetCurrentWindowHandle'
W3C_GET_WINDOW_HANDLES = 'w3cGetWindowHandles'
W3C_GET_WINDOW_POSITION = 'w3cGetWindowPosition'
W3C_GET_WINDOW_SIZE = 'w3cGetWindowSize'
W3C_MAXIMIZE_WINDOW = 'w3cMaximizeWindow'
W3C_SET_ALERT_VALUE = 'w3cSetAlertValue'
W3C_SET_WINDOW_POSITION = 'w3cSetWindowPosition'
W3C_SET_WINDOW_SIZE = 'w3cSetWindowSize'
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 39/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
SUCCESS = 0
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 40/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
class selenium.webdriver.remote.errorhandler.ErrorHandler
Bases: object
check_response (response)
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.
__init__ (mask)
x.__init__(…) initializes x; see help(type(x)) for signature
airplane_mode
data
wifi
__init__ (driver)
x.__init__(…) initializes x; see help(type(x)) for signature
set_network_connection (network)
Set the network connection for the remote device.
driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)
context
returns the current context (Native or WebView).
contexts
returns a list of available contexts
network_connection
Bases: object
Any path subtitutions required for the URL mapped to the command should be included in the command parameters.
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
selenium.webdriver.remote.utils.format_json (json_struct)
selenium.webdriver.remote.utils.load_json (s)
selenium.webdriver.remote.utils.unzip_to_temp_dir (zip_file_name)
Unzip zipfile to a temporary directory.
The directory of the unzipped files is returned if success, otherwise None is returned.
Controls the IEServerDriver and allows you to drive Internet Explorer v: latest
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 42/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Starts the service and then creates new instance of chrome driver.
Args: executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
capabilities: capabilities Dictionary object
port - port you would like the service to run, if left as 0, a free port will be found.
timeout - no longer used, kept for backward compatibility
host - IP address for the service
log_level - log level you would like the service to run.
service_log_path - target of logging of service, may be “stdout”, “stderr” or file path.
options - IE Options instance, providing additional IE options
ie_options - Deprecated argument for options
desired_capabilities - alias of capabilities; this will make the signature consistent with RemoteWebDriver.
log_file - Deprecated argument for service_log_path
keep_alive - Whether to configure RemoteConnection to use HTTP keep-alive.
create_options ()
quit ()
Quits the driver and closes every associated window.
Usage: driver.quit()
Controls the new OperaDriver and allows you to drive the Opera browser based on Chromium.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 43/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
class ServiceType
CHROMIUM = 2
Starts the service and then creates new instance of the driver.
v: latest
Args: executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
port - port you would like the service to run, if left as 0, a free port will be found.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 44/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
desired_capabilities: Dictionary object with non-browser specific capabilities only, such as “proxy” or
“loggingPref”.
service_args : A List of command line arguments to pass to PhantomJS
service_log_path: Path for phantomjs service to log to.
quit ()
Closes the browser and shuts down the PhantomJS executable that is started when starting the PhantomJS
command_line_args ()
send_remote_shutdown_command ()
service_url
Gets the url of the GhostDriver Service
Args: port - The port on which the safaridriver service should listen for new connections. If zero, a free port will be
found.
executable_path - Path to a custom safaridriver executable to be used. If absent, /usr/bin/safaridriver is used.
reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that
was launched externally.
desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
quiet - If True, the driver’s stdout and stderr is suppressed.
keep_alive - Whether to configure SafariRemoteConnection to use
HTTP keep-alive. Defaults to False.
debug ()
v: latest
get_permission (permission)
quit ()
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 45/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
Closes the browser and shuts down the SafariDriver executable that is started when starting the SafariDriver
service_url
Gets the url of the SafariDriver Service
__init__ (webelement)
Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an
UnexpectedTagNameException is thrown.
Select(driver.find_element_by_tag_name(“select”)).select_by_index(2)
deselect_all ()
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)
Deselect the option at the given index. This is done by examing the “index” attribute of an element, and not merely by
counting.
deselect_by_value (value)
Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect an option
like:
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 46/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
deselect_by_visible_text (text)
Deselect all options that display text matching the argument. That is, when given “Bar” this would deselect an option like:
<option value=”foo”>Bar</option>
select_by_index (index)
Select the option at the given index. This is done by examing the “index” attribute of an element, and not merely by
counting.
select_by_value (value)
Select all options that have a value matching the argument. That is, when given “foo” this would select an option like:
<option value=”foo”>Bar</option>
select_by_visible_text (text)
Select all options that display text matching the argument. That is, when given “Bar” this would select an option like:
<option value=”foo”>Bar</option>
Args: text - The visible text to match against
throws NoSuchElementException If there is no option with specisied text in SELECT
all_selected_options
Returns a list of all selected options belonging to this select tag
first_selected_option
The first selected option in this select tag (or the currently selected option in a normal select)
options
Returns a list of all options belonging to this select tag
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 47/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
until_not(lambda x: x.find_element_by_id(“someId”).is_displayed())
until (method, message='')
Calls the method provided with the driver as an argument until the return value is not False.
Example:
print(Color.from_string('#00ff33').rgba)
print(Color.from_string('rgb(1, 255, 3)').hex)
print(Color.from_string('blue').rgba)
rgb
rgba
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 48/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
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 ()
close ()
find_element_by_class_name (name)
find_element_by_css_selector (css_selector)
find_element_by_id (id_)
find_element_by_link_text (link_text)
find_element_by_name (name)
find_element_by_partial_link_text (link_text)
find_element_by_tag_name (name)
find_element_by_xpath (xpath)
find_elements_by_class_name (name)
find_elements_by_css_selector (css_selector)
find_elements_by_id (id_)
find_elements_by_link_text (text)
find_elements_by_name (name)
find_elements_by_partial_link_text (link_text)
find_elements_by_tag_name (name)
find_elements_by_xpath (xpath)
forward ()
get (url)
quit ()
wrapped_driver
Returns the WebDriver instance wrapped by this EventsFiringWebDriver
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 49/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
clear ()
click ()
find_element_by_class_name (name)
find_element_by_css_selector (css_selector)
find_element_by_id (id_)
find_element_by_link_text (link_text)
find_element_by_name (name)
find_element_by_partial_link_text (link_text)
find_element_by_tag_name (name)
find_element_by_xpath (xpath)
find_elements_by_class_name (name)
find_elements_by_css_selector (css_selector)
find_elements_by_id (id_)
find_elements_by_link_text (link_text)
find_elements_by_name (name)
find_elements_by_partial_link_text (link_text)
find_elements_by_tag_name (name)
find_elements_by_xpath (xpath)
send_keys (*value)
wrapped_element
Returns the WebElement wrapped by this EventFiringWebElement instance
after_close (driver)
after_navigate_back (driver)
after_navigate_forward (driver)
v: latest
after_navigate_to (url, driver)
after_quit (driver)
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 50/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
before_close (driver)
before_navigate_back (driver)
before_navigate_forward (driver)
before_quit (driver)
__init__ ()
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation to locate an element and check if the selection state specified is in that state. locator is a tuple of (by, path)
is_selected is a boolean
An expectation for the element to be located is selected. locator is a tuple of (by, path)
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking if the given element is selected. element is WebElement object is_selected is a Boolean.”
An Expectation for checking an element is visible and enabled such that you can click it.
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 51/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
__init__ (element)
x.__init__(…) initializes x; see help(type(x)) for signature
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.
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
An Expectation for checking that an element is either invisible or not present on the DOM.
An Expectation for checking that an element is either invisible or not present on the DOM.
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation that a new window will be opened and have the number of windows handles increase
__init__ (current_handles)
x.__init__(…) initializes x; see help(type(x)) for signature
__init__ (num_windows)
x.__init__(…) initializes x; see help(type(x)) for signature
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 52/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
An expectation for checking that there is at least one element present on a web page. locator is used to find the element
returns the list of WebElements once they are located
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the
element is visible. locator - used to find the element returns the WebElement once it is located
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
Wait until an element is no longer attached to the DOM. element is the element to wait for. returns False if the element is still
attached to the DOM, true otherwise.
__init__ (element)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking if the given text is present in the specified element. locator, text
An expectation for checking if the given text is present in the element’s locator, text
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
__init__ (title)
x.__init__(…) initializes x; see help(type(x)) for signature
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. v: latest
__init__ (title)
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 53/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
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.
__init__ (url)
x.__init__(…) initializes x; see help(type(x)) for signature
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
__init__ (url)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking the current url. pattern is the expected pattern, which must be an exact match returns True if the
url matches, false otherwise.
__init__ (pattern)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking the current url. url is the expected url, which must be an exact match returns True if the url
matches, false otherwise.
__init__ (url)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the
element is not only displayed but also has a height and width that is greater than 0. element is the WebElement returns the
(same) WebElement once it is visible
__init__ (element)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking that all elements are present on the DOM of a page and visible. Visibility means that the elements
are not only displayed but also has a height and width that is greater than 0. locator - used to find the elements returns the list
of WebElements once they are located and visible v: latest
__init__ (locator)
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 54/55
10/27/2018 7. WebDriver API — Selenium Python Bindings 2 documentation
An expectation for checking that there is at least one element visible on a web page. locator is used to find the element returns
the list of WebElements once they are located
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is
not only displayed but also has a height and width that is greater than 0. locator - used to find the element returns the
WebElement once it is located and visible
__init__ (locator)
x.__init__(…) initializes x; see help(type(x)) for signature
v: latest
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.location_once_scrolled_into_view 55/55