capybara.selenium package¶
Submodules¶
capybara.selenium.browser module¶
-
capybara.selenium.browser.
get_browser
(browser_name, capabilities=None, **options)[source]¶ Returns an instance of the given browser with the given capabilities.
Parameters: - browser_name (str) – The name of the desired browser.
- capabilities (Dict[str, str | bool], optional) – The desired capabilities of the browser. Defaults to None.
- options – Arbitrary keyword arguments for the browser-specific subclass of
webdriver.Remote
.
Returns: An instance of the desired browser.
Return type: WebDriver
capybara.selenium.driver module¶
-
class
capybara.selenium.driver.
Driver
(app, browser='firefox', clear_local_storage=False, clear_session_storage=False, desired_capabilities=None, **options)[source]¶ Bases:
capybara.driver.base.Base
A Capybara driver that uses Selenium WebDriver to drive a real browser.
Parameters: - app (object) – The WSGI-compliant app to drive.
- browser (str, optional) – The name of the browser to use. Defaults to “firefox”.
- clear_local_storage (bool, optional) – Whether to clear local storage on reset. Defaults to False.
- clear_session_storage (bool, optional) – Whether to clear session storage on reset. Defaults to False.
- desired_capabilities (Dict[str, str | bool], optional) – Desired capabilities of the underlying browser. Defaults to a set of reasonable defaults provided by Selenium.
- options – Arbitrary keyword arguments for the underlying Selenium driver.
-
accept_modal
(modal_type, text=None, response=None, wait=None)[source]¶ Accepts the modal that appears matching the given type and, optionally, text.
Parameters: - modal_type (str) – The type of modal that should be accepted.
- text (str | RegexObject, optional) – Text that is expected to appear in the modal.
- response (str, optional) – Text to enter for a response, if applicable.
- wait (int, optional) – The number of seconds to wait for the modal to appear.
-
close_window
(handle)[source]¶ Closes the window with the given handle.
Parameters: handle (object) – The handle for the desired window.
-
current_url
¶ str – The current URL.
-
current_window_handle
¶ object – The current window handle.
-
dismiss_modal
(modal_type, text=None, wait=None)[source]¶ Dismisses the modal that appears matching the given type and, optionally, text.
Parameters: - modal_type (str) – The type of modal that should be dismissed.
- text (str | RegexObject, optional) – Text that is expected to appear in the modal.
- wait (int, optional) – The number of seconds to wait for the modal to appear.
-
evaluate_async_script
(script, *args)[source]¶ Evaluates the given JavaScript and obtains the result from a callback function.
Parameters: - script (str) – A string of JavaScript to evaluate.
- *args – Variable length argument list to pass to the executed JavaScript string.
Returns: The result of the evaluated JavaScript.
Return type: object
-
evaluate_script
(script, *args)[source]¶ Evaluates and returns the result of the given JavaScript.
Parameters: - script (str) – A string of JavaScript to evaluate.
- *args – Variable length argument list to pass to the executed JavaScript string.
Returns: The result of the evaluated JavaScript.
Return type: object
-
execute_script
(script, *args)[source]¶ Executes the given script.
Parameters: - script (str) – A JavaScript string to execute.
- *args – Variable length argument list to pass to the executed JavaScript string.
-
html
¶ str – A snapshot of the DOM of the current document, as it looks right now.
-
invalid_element_errors
¶ Tuple[Exception] – A tuple of exceptions that indicate an element is invalid.
-
needs_server
¶ bool – Whether this driver needs to communicate with a real HTTP server.
-
no_such_window_error
¶ Exception – The error that is thrown when a window cannot be found.
-
resize_window_to
(handle, width, height)[source]¶ Resizes the given window handle to the given dimensions.
Parameters: - handle (object) – The driver handle for the window.
- width (int) – The desired window width.
- height (int) – The desired window height.
-
save_screenshot
(path, **kwargs)[source]¶ Saves a screenshot of the current state of the page.
Parameters: - path (str) – The path to where it should be saved.
- **kwargs – Arbitrary keywords arguments for the driver.
-
switch_to_frame
(frame)[source]¶ Switch to the given frame.
Parameters: frame (Element | str) – The element of the desired frame, or “parent”.
-
switch_to_window
(handle)[source]¶ Switches to the given window handle.
Parameters: handle (object) – The handle for the desired window.
-
text
¶
-
title
¶ str – The current page title.
-
window_handles
¶ List[object] – The handles for all opened windows.
capybara.selenium.node module¶
-
class
capybara.selenium.node.
Node
(driver, native)[source]¶ Bases:
capybara.driver.node.Node
-
all_text
¶ str – All of the text of the node.
-
checked
¶ bool – Whether this node is checked.
-
disabled
¶ bool – Whether this node is disabled.
-
drag_to
(element)[source]¶ Drag the element to the given other element.
source = page.find("#foo") target = page.find("#bar") source.drag_to(target)
Parameters: node (Element) – The element to drag to.
-
multiple
¶ bool – Whether this is a multi-select node.
-
path
¶ str – An XPath expression describing where on the page the node can be found.
-
readonly
¶ bool – Whether the node is read-only.
-
selected
¶ bool – Whether this node is selected.
-
send_keys
(*args)[source]¶ Send keystrokes to the node.
Examples:
from selenium.webdriver.common.keys import Keys element.send_keys("foo") # => value: "foo" element.send_keys("tet", Keys.LEFT, "s") # => value: "test"
Parameters: *args – Variable length list of keys to send.
-
set
(value, clear=None)[source]¶ Sets the value of this node.
Parameters: - value (bool | str) – The desired value.
- **options – Driver-specific options for how to set a value on a node.
-
style
(styles)[source]¶ Returns the computed values of the given styles.
Parameters: styles (List[str]) – The desired styles. Returns: The computed styles. Return type: Dict[str, str]
-
tag_name
¶ str – The tag name of the node.
-
value
¶ str – The value of the node.
-
visible
¶ bool – Whether or not the node is visible.
-
visible_text
¶ str – Only the visible text of the node.
-