Struct fantoccini::Client [−][src]
pub struct Client { /* fields omitted */ }
Expand description
A WebDriver client tied to a single browser session.
Use ClientBuilder
to create a new session.
Note that most callers should explicitly call Client::close
, and wait for the returned
future before exiting. Not doing so may result in the WebDriver session not being cleanly
closed, which is particularly important for some drivers, such as geckodriver, where
multiple simulatenous sessions are not supported. If close
is not explicitly called, a
session close request will be spawned on the given handle
when the last instance of this
Client
is dropped.
Implementations
👎 Deprecated since 0.17.1: Prefer ClientBuilder::native
This is supported on crate feature native-tls
only.
Prefer ClientBuilder::native
native-tls
only.Connect to the WebDriver host running the given address.
This connects using a platform-native TLS library, and is only available with the
native-tls
feature. To customize, use ClientBuilder
instead.
pub async fn with_capabilities_and_connector<C>(
webdriver: &str,
cap: &Capabilities,
connector: C
) -> Result<Self, NewSessionError> where
C: Connect + Unpin + 'static + Clone + Send + Sync,
[src]
pub async fn with_capabilities_and_connector<C>(
webdriver: &str,
cap: &Capabilities,
connector: C
) -> Result<Self, NewSessionError> where
C: Connect + Unpin + 'static + Clone + Send + Sync,
[src]Connect to the WebDriver host running the given address.
Prefer using ClientBuilder
over calling this method directly.
The given capabilities will be requested in alwaysMatch
or desiredCapabilities
depending on the protocol version supported by the server.
Returns a future that resolves to a handle for issuing additional WebDriver tasks.
Get the unique session ID assigned by the WebDriver server to this client.
Set the User Agent string to use for all subsequent requests.
Get the current User Agent string.
Terminate the WebDriver session.
Normally, a shutdown of the WebDriver connection will be initiated when the last clone of a
Client
is dropped. Specifically, the shutdown request will be issued using the tokio
Handle
given when creating this Client
. This in turn means that any errors will be
dropped.
This function is safe to call multiple times, but once it has been called on one instance
of a Client
, all requests to other instances of that Client
will fail.
This function may be useful in conjunction with raw_client_for
, as it allows you to close
the automated browser window while doing e.g., a large download.
Mark this client’s session as persistent.
After all instances of a Client
have been dropped, we normally shut down the WebDriver
session, which also closes the associated browser window or tab. By calling this method,
the shutdown command will not be sent to this client’s session, meaning its window or tab
will remain open.
Note that an explicit call to Client::close
will still terminate the session.
This function is safe to call multiple times.
Navigate directly to the given URL.
See 9.1 Navigate To of the WebDriver standard.
Retrieve the currently active URL for this session.
See 9.2 Get Current URL of the WebDriver standard.
Go back to the previous page.
See 9.3 Back of the WebDriver standard.
Gets the current window handle.
See 10.1 Get Window Handle of the WebDriver standard.
Closes the current window.
Will close the session if no other windows exist.
Closing a window will not switch the client to one of the remaining windows.
The switching must be done by calling switch_to_window
using a still live window
after the current window has been closed.
See 10.2 Close Window of the WebDriver standard.
Switches to the chosen window.
See 10.3 Switch To Window of the WebDriver standard.
Gets a list of all active windows (and tabs)
See 10.4 Get Window Handles of the WebDriver standard.
Creates a new window. If is_tab
is true
, then a tab will be created instead.
Windows are treated the same as tabs by the WebDriver protocol. The functions new_window
,
switch_to_window
, close_window
, window
and windows
all operate on both tabs and
windows.
This operation is only in the editor’s draft of the next iteration of the WebDriver
protocol, and may thus not be supported by all WebDriver implementations. For example, if
you’re using geckodriver
, you will need geckodriver > 0.24
and firefox > 66
to use
this feature.
See 11.5 New Window of the editor’s draft standard.
Switches to the frame specified at the index.
See 10.5 Switch To Frame of the WebDriver standard.
Switches to the parent of the frame the client is currently contained within.
See 10.6 Switch To Parent Frame of the WebDriver standard.
Sets the x, y, width, and height properties of the current window.
See 10.7.2 Set Window Rect of the WebDriver standard.
Gets the x, y, width, and height properties of the current window.
See 10.7.1 Get Window Rect of the WebDriver standard.
Sets the x, y, width, and height properties of the current window.
See 10.7.2 Set Window Rect of the WebDriver standard.
Gets the width and height of the current window.
See 10.7.1 Get Window Rect of the WebDriver standard.
Sets the x, y, width, and height properties of the current window.
See 10.7.2 Set Window Rect of the WebDriver standard.
Gets the x and y top-left coordinate of the current window.
See 10.7.1 Get Window Rect of the WebDriver standard.
Find an element on the page that matches the given Locator
.
See 12.2 Find Element of the WebDriver standard.
Find all elements on the page that match the given Locator
.
See 12.3 Find Elements of the WebDriver standard.
Get the active element for this session.
The “active” element is the Element
within the DOM that currently has focus. This will
often be an <input>
or <textarea>
element that currently has the text selection, or
another input element such as a checkbox or radio button. Which elements are focusable
depends on the platform and browser configuration.
If no element has focus, the result may be the page body or a NoSuchElement
error.
See 12.6 Get Active Element of the WebDriver standard.
Get the HTML source for the current page.
See 15.1 Get Page Source of the WebDriver standard.
Execute the given JavaScript script
in the current browser session.
args
is available to the script inside the arguments
array. Since Element
implements
Serialize
, you can also provide serialized Element
s as arguments, and they will
correctly deserialize to DOM elements on the other side.
To retrieve the value of a variable, return
has to be used in the JavaScript code.
See 15.2.1 Execute Script of the WebDriver standard.
Execute the given async JavaScript script
in the current browser session.
The provided JavaScript has access to args
through the JavaScript variable arguments
.
The arguments
array also holds an additional element at the end that provides a completion callback
for the asynchronous code.
Since Element
implements Serialize
, you can also provide serialized Element
s as arguments, and they will
correctly deserialize to DOM elements on the other side.
Examples
Call a web API from the browser and retrieve the value asynchronously
const JS: &'static str = r#" const [date, callback] = arguments; fetch(`http://weather.api/${date}/hourly`) // whenever the HTTP Request completes, // send the value back to the Rust context .then(data => { callback(data.json()) }) "#; let weather = client.execute_async(JS, vec![date]).await?;
See 15.2.2 Execute Async Script of the WebDriver standard.
Get a PNG-encoded screenshot of the current page.
See 19.1 Take Screenshot of the WebDriver standard.
Get a PNG-encoded screenshot of an element.
See 19.2 Take Element Screenshot of the WebDriver standard.
Operations that wait for a change on the page.
Wait for the given function to return true
before proceeding.
This can be useful to wait for something to appear on the page before interacting with it.
While this currently just spins and yields, it may be more efficient than this in the
future. In particular, in time, it may only run is_ready
again when an event occurs on
the page.
Wait for the given element to be present on the page.
This can be useful to wait for something to appear on the page before interacting with it.
While this currently just spins and yields, it may be more efficient than this in the
future. In particular, in time, it may only run is_ready
again when an event occurs on
the page.
Wait for the page to navigate to a new URL before proceeding.
If the current
URL is not provided, self.current_url()
will be used. Note however that
this introduces a race condition: the browser could finish navigating before we call
current_url()
, which would lead to an eternal wait.
Raw access to the WebDriver instance.
Issue an HTTP request to the given url
with all the same cookies as the current session.
Calling this method is equivalent to calling with_raw_client_for
with an empty closure.
Build and issue an HTTP request to the given url
with all the same cookies as the current
session.
Before the HTTP request is issued, the given before
closure will be called with a handle
to the Request
about to be sent.
Get all cookies associated with the current document.
See 16.1 Get All Cookies of the WebDriver standard.
Get a single named cookie associated with the current document.
See 16.2 Get Named Cookie of the WebDriver standard.
Delete a single cookie from the current document.
See 16.4 Delete Cookie of the WebDriver standard.
Delete all cookies from the current document.
See 16.5 Delete All Cookies of the WebDriver standard.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more