[−][src]Struct fantoccini::Client
A WebDriver client tied to a single browser session.
Methods
impl Client
[src]
pub async fn new<'_>(webdriver: &'_ str) -> Result<Self, NewSessionError>
[src]
Create a new Client
associated with a new WebDriver session on the server at the given
URL.
Calls with_capabilities
with an empty capabilities list.
pub async fn with_capabilities<'_>(
webdriver: &'_ str,
cap: Capabilities
) -> Result<Self, NewSessionError>
[src]
webdriver: &'_ str,
cap: Capabilities
) -> Result<Self, NewSessionError>
Create a new Client
associated with a new WebDriver session on the server at the given
URL.
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.
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.
pub async fn session_id<'_>(&'_ mut self) -> Result<Option<String>, CmdError>
[src]
Get the session ID assigned by the WebDriver server to this client.
pub async fn set_ua<'_, S: Into<String>>(
&'_ mut self,
ua: S
) -> Result<(), CmdError>
[src]
&'_ mut self,
ua: S
) -> Result<(), CmdError>
Set the User Agent string to use for all subsequent requests.
pub async fn get_ua<'_>(&'_ mut self) -> Result<Option<String>, CmdError>
[src]
Get the current User Agent string.
pub async fn close<'_>(&'_ mut self) -> Result<(), CmdError>
[src]
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.
pub async fn persist<'_>(&'_ mut self) -> Result<(), CmdError>
[src]
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.
pub async fn set_window_rect<'_>(
&'_ mut self,
x: i32,
y: i32,
width: i32,
height: i32
) -> Result<(), CmdError>
[src]
&'_ mut self,
x: i32,
y: i32,
width: i32,
height: i32
) -> Result<(), CmdError>
Sets the x, y, width, and height properties of the current window.
All values must be >= 0
or you will get a CmdError::InvalidArgument
.
pub async fn get_window_rect<'_>(
&'_ mut self
) -> Result<(u64, u64, u64, u64), CmdError>
[src]
&'_ mut self
) -> Result<(u64, u64, u64, u64), CmdError>
Gets the x, y, width, and height properties of the current window.
pub async fn set_window_size<'_>(
&'_ mut self,
width: i32,
height: i32
) -> Result<(), CmdError>
[src]
&'_ mut self,
width: i32,
height: i32
) -> Result<(), CmdError>
Sets the x, y, width, and height properties of the current window.
All values must be >= 0
or you will get a CmdError::InvalidArgument
.
pub async fn get_window_size<'_>(&'_ mut self) -> Result<(u64, u64), CmdError>
[src]
Gets the width and height of the current window.
pub async fn set_window_position<'_>(
&'_ mut self,
x: i32,
y: i32
) -> Result<(), CmdError>
[src]
&'_ mut self,
x: i32,
y: i32
) -> Result<(), CmdError>
Sets the x, y, width, and height properties of the current window.
All values must be >= 0
or you will get a CmdError::InvalidArgument
.
pub async fn get_window_position<'_>(
&'_ mut self
) -> Result<(u64, u64), CmdError>
[src]
&'_ mut self
) -> Result<(u64, u64), CmdError>
Gets the x and y top-left coordinate of the current window.
pub async fn goto<'_, '_>(&'_ mut self, url: &'_ str) -> Result<(), CmdError>
[src]
Navigate directly to the given URL.
pub async fn current_url<'_>(&'_ mut self) -> Result<Url, CmdError>
[src]
Retrieve the currently active URL for this session.
pub async fn screenshot<'_>(&'_ mut self) -> Result<Vec<u8>, CmdError>
[src]
Get a PNG-encoded screenshot of the current page.
pub async fn source<'_>(&'_ mut self) -> Result<String, CmdError>
[src]
Get the HTML source for the current page.
pub async fn back<'_>(&'_ mut self) -> Result<(), CmdError>
[src]
Go back to the previous page.
pub async fn refresh<'_>(&'_ mut self) -> Result<(), CmdError>
[src]
Refresh the current previous page.
pub async fn execute<'_, '_>(
&'_ mut self,
script: &'_ str,
__arg2: Vec<Json>
) -> Result<Json, CmdError>
[src]
&'_ mut self,
script: &'_ str,
__arg2: Vec<Json>
) -> Result<Json, CmdError>
Execute the given JavaScript script
in the current browser session.
args
is available to the script inside the arguments
array. Since Element
implements
ToJson
, you can also provide serialized Element
s as arguments, and they will correctly
serialize to DOM elements on the other side.
To retrieve the value of a variable, return
has to be used in the JavaScript code.
pub async fn raw_client_for<'_, '_>(
&'_ mut self,
method: Method,
url: &'_ str
) -> Result<Response<Body>, CmdError>
[src]
&'_ mut self,
method: Method,
url: &'_ str
) -> Result<Response<Body>, CmdError>
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.
pub async fn with_raw_client_for<'_, '_, F>(
&'_ mut self,
method: Method,
url: &'_ str,
before: F
) -> Result<Response<Body>, CmdError> where
F: FnOnce(Builder) -> Request<Body>,
[src]
&'_ mut self,
method: Method,
url: &'_ str,
before: F
) -> Result<Response<Body>, CmdError> where
F: FnOnce(Builder) -> Request<Body>,
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.
pub async fn frame(__arg0: Self, index: Option<u16>) -> Result<Client, CmdError>
[src]
Switches to the frame specified at the index.
pub async fn parent_frame(__arg0: Self) -> Result<Client, CmdError>
[src]
Switches to the parent of the frame the client is currently contained within.
pub async fn find<'_, '_>(
&'_ mut self,
search: Locator<'_>
) -> Result<Element, CmdError>
[src]
&'_ mut self,
search: Locator<'_>
) -> Result<Element, CmdError>
Find an element on the page.
pub async fn find_all<'_, '_>(
&'_ mut self,
search: Locator<'_>
) -> Result<Vec<Element>, CmdError>
[src]
&'_ mut self,
search: Locator<'_>
) -> Result<Vec<Element>, CmdError>
Find elements on the page.
pub async fn wait_for<'_, F, FF>(
&'_ mut self,
__arg1: F
) -> Result<(), CmdError> where
F: FnMut(&mut Client) -> FF,
FF: Future<Output = Result<bool, CmdError>>,
[src]
&'_ mut self,
__arg1: F
) -> Result<(), CmdError> where
F: FnMut(&mut Client) -> FF,
FF: Future<Output = Result<bool, CmdError>>,
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.
pub async fn wait_for_find<'_, '_>(
&'_ mut self,
search: Locator<'_>
) -> Result<Element, CmdError>
[src]
&'_ mut self,
search: Locator<'_>
) -> Result<Element, CmdError>
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.
pub async fn wait_for_navigation<'_>(
&'_ mut self,
current: Option<Url>
) -> Result<(), CmdError>
[src]
&'_ mut self,
current: Option<Url>
) -> Result<(), CmdError>
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.
pub async fn form<'_, '_>(
&'_ mut self,
search: Locator<'_>
) -> Result<Form, CmdError>
[src]
&'_ mut self,
search: Locator<'_>
) -> Result<Form, CmdError>
Locate a form on the page.
Through the returned Form
, HTML forms can be filled out and submitted.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,