Struct fantoccini::Client [−][src]
pub struct Client(_);
A WebDriver client tied to a single browser session.
Methods
impl Client
[src]
impl Client
pub fn new(
webdriver: &str,
handle: &Handle
) -> impl Future<Item = Self, Error = NewSessionError> + 'static
[src]
pub fn new(
webdriver: &str,
handle: &Handle
) -> impl Future<Item = Self, Error = NewSessionError> + 'static
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 fn with_capabilities(
webdriver: &str,
cap: Capabilities,
handle: &Handle
) -> impl Future<Item = Self, Error = NewSessionError> + 'static
[src]
pub fn with_capabilities(
webdriver: &str,
cap: Capabilities,
handle: &Handle
) -> impl Future<Item = Self, Error = NewSessionError> + 'static
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 fn session_id(&self) -> String
[src]
pub fn session_id(&self) -> String
Get the session ID assigned by the WebDriver server to this client.
pub fn set_ua<S: Into<String>>(&mut self, ua: S)
[src]
pub fn set_ua<S: Into<String>>(&mut self, ua: S)
Set the User Agent string to use for all subsequent requests.
pub fn close(
&self
) -> Option<impl Future<Item = (), Error = Error>>
[src]
pub fn close(
&self
) -> Option<impl Future<Item = (), Error = Error>>
Terminate the connection to the webservice.
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, and that the teardown may not even occur if the reactor does not continue being
turned.
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. The returned
Option
will only be true the first time close
is called.
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 fn set_window_rect(
&self,
x: i32,
y: i32,
width: i32,
height: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn set_window_rect(
&self,
x: i32,
y: i32,
width: i32,
height: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
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 fn get_window_rect(
&self
) -> impl Future<Item = (u64, u64, u64, u64), Error = CmdError> + 'static
[src]
pub fn get_window_rect(
&self
) -> impl Future<Item = (u64, u64, u64, u64), Error = CmdError> + 'static
Gets the x, y, width, and height properties of the current window.
pub fn set_window_size(
&self,
width: i32,
height: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn set_window_size(
&self,
width: i32,
height: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
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 fn get_window_size(
&self
) -> impl Future<Item = (u64, u64), Error = CmdError> + 'static
[src]
pub fn get_window_size(
&self
) -> impl Future<Item = (u64, u64), Error = CmdError> + 'static
Gets the width and height of the current window.
pub fn set_window_position(
&self,
x: i32,
y: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn set_window_position(
&self,
x: i32,
y: i32
) -> impl Future<Item = Self, Error = CmdError> + 'static
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 fn get_window_position(
&self
) -> impl Future<Item = (u64, u64), Error = CmdError> + 'static
[src]
pub fn get_window_position(
&self
) -> impl Future<Item = (u64, u64), Error = CmdError> + 'static
Gets the x and y top-left coordinate of the current window.
pub fn goto(
&self,
url: &str
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn goto(
&self,
url: &str
) -> impl Future<Item = Self, Error = CmdError> + 'static
Navigate directly to the given URL.
pub fn current_url(
&self
) -> impl Future<Item = Url, Error = CmdError> + 'static
[src]
pub fn current_url(
&self
) -> impl Future<Item = Url, Error = CmdError> + 'static
Retrieve the currently active URL for this session.
pub fn source(
&self
) -> impl Future<Item = String, Error = CmdError> + 'static
[src]
pub fn source(
&self
) -> impl Future<Item = String, Error = CmdError> + 'static
Get the HTML source for the current page.
pub fn back(
&self
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn back(
&self
) -> impl Future<Item = Self, Error = CmdError> + 'static
Go back to the previous page.
pub fn refresh(
&self
) -> impl Future<Item = Self, Error = CmdError> + 'static
[src]
pub fn refresh(
&self
) -> impl Future<Item = Self, Error = CmdError> + 'static
Refresh the current previous page.
pub fn execute(
&self,
script: &str,
args: Vec<Json>
) -> impl Future<Item = Json, Error = CmdError> + 'static
[src]
pub fn execute(
&self,
script: &str,
args: Vec<Json>
) -> impl Future<Item = Json, Error = CmdError> + 'static
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.
pub fn raw_client_for(
&self,
method: Method,
url: &str
) -> impl Future<Item = Response, Error = CmdError> + 'static
[src]
pub fn raw_client_for(
&self,
method: Method,
url: &str
) -> impl Future<Item = Response, Error = CmdError> + 'static
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 fn with_raw_client_for<F>(
&self,
method: Method,
url: &str,
before: F
) -> impl Future<Item = Response, Error = CmdError> + 'static where
F: FnOnce(&mut Request) + 'static,
[src]
pub fn with_raw_client_for<F>(
&self,
method: Method,
url: &str,
before: F
) -> impl Future<Item = Response, Error = CmdError> + 'static where
F: FnOnce(&mut Request) + 'static,
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 fn find(
&self,
search: Locator
) -> impl Future<Item = Element, Error = CmdError> + 'static
[src]
pub fn find(
&self,
search: Locator
) -> impl Future<Item = Element, Error = CmdError> + 'static
Find an element on the page.
ⓘImportant traits for &'a mut Rpub fn wait_for<F>(&mut self, is_ready: F) -> &mut Self where
F: FnMut(Client) -> bool,
[src]
pub fn wait_for<F>(&mut self, is_ready: F) -> &mut Self where
F: FnMut(Client) -> bool,
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 fn wait_for_find<'a>(
&'a self,
search: Locator<'a>
) -> impl Future<Item = Element, Error = CmdError> + 'a
[src]
pub fn wait_for_find<'a>(
&'a self,
search: Locator<'a>
) -> impl Future<Item = Element, Error = CmdError> + 'a
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.
pub fn form(
&self,
search: Locator
) -> impl Future<Item = Form, Error = CmdError> + 'static
[src]
pub fn form(
&self,
search: Locator
) -> impl Future<Item = Form, Error = CmdError> + 'static
Locate a form on the page.
Through the returned Form
, HTML forms can be filled out and submitted.