capybara.driver package¶
Submodules¶
capybara.driver.base module¶
-
class
capybara.driver.base.
Base
[source]¶ Bases:
object
The base class for drivers used by sessions.
-
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.
-
frame_title
¶ str – The title for the current frame.
-
frame_url
¶ str – The URL for the current frame.
-
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.
-
title
¶ str – The current page title.
-
window_handles
¶ List[object] – The handles for all opened windows.
-
capybara.driver.node module¶
-
class
capybara.driver.node.
Node
(driver, native)[source]¶ Bases:
object
The base class for nodes returned by a driver.
Parameters: - driver (driver.Base) – The driver used to find this node.
- native (object) – The native element object returned by the driver’s browser.
-
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
(node)[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, **options)[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.
-
text
¶ str – The text 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.