[][src]Struct fantoccini::Client

pub struct Client { /* fields omitted */ }

A WebDriver client tied to a single browser session.

Methods

impl Client[src]

pub fn new(webdriver: &str) -> impl Future<Item = Self, Error = 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 fn with_capabilities(
    webdriver: &str,
    cap: Capabilities
) -> impl Future<Item = Self, Error = NewSessionError>
[src]

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(
    &mut self
) -> impl Future<Item = Option<String>, Error = CmdError>
[src]

Get the session ID assigned by the WebDriver server to this client.

pub fn set_ua<S: Into<String>>(
    &mut self,
    ua: S
) -> impl Future<Item = (), Error = CmdError>
[src]

Set the User Agent string to use for all subsequent requests.

pub fn get_ua(&mut self) -> impl Future<Item = Option<String>, Error = CmdError>[src]

Get the current User Agent string.

pub fn close(&mut self) -> impl Future<Item = (), Error = CmdError>[src]

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.

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 fn set_window_rect(
    &mut self,
    x: i32,
    y: i32,
    width: i32,
    height: i32
) -> impl Future<Item = (), Error = CmdError>
[src]

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(
    &mut self
) -> impl Future<Item = (u64, u64, u64, u64), Error = CmdError>
[src]

Gets the x, y, width, and height properties of the current window.

pub fn set_window_size(
    &mut self,
    width: i32,
    height: i32
) -> impl Future<Item = (), Error = CmdError>
[src]

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(
    &mut self
) -> impl Future<Item = (u64, u64), Error = CmdError>
[src]

Gets the width and height of the current window.

pub fn set_window_position(
    &mut self,
    x: i32,
    y: i32
) -> impl Future<Item = (), Error = CmdError>
[src]

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(
    &mut self
) -> impl Future<Item = (u64, u64), Error = CmdError>
[src]

Gets the x and y top-left coordinate of the current window.

pub fn goto(self, url: &str) -> impl Future<Item = Self, Error = CmdError>[src]

Navigate directly to the given URL.

pub fn current_url(&mut self) -> impl Future<Item = Url, Error = CmdError>[src]

Retrieve the currently active URL for this session.

pub fn screenshot(&mut self) -> impl Future<Item = Vec<u8>, Error = CmdError>[src]

Get a PNG-encoded screenshot of the current page.

pub fn source(&mut self) -> impl Future<Item = String, Error = CmdError>[src]

Get the HTML source for the current page.

pub fn back(&mut self) -> impl Future<Item = (), Error = CmdError>[src]

Go back to the previous page.

pub fn refresh(&mut self) -> impl Future<Item = (), Error = CmdError>[src]

Refresh the current previous page.

pub fn execute(
    &mut self,
    script: &str,
    args: Vec<Json>
) -> impl Future<Item = Json, Error = CmdError>
[src]

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 Elements 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 fn raw_client_for<'a>(
    self,
    method: Method,
    url: &str
) -> impl Future<Item = Response<Body>, Error = CmdError>
[src]

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<Body>, Error = CmdError> where
    F: FnOnce(Builder) -> Request<Body>, 
[src]

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(
    &mut self,
    search: Locator
) -> impl Future<Item = Element, Error = CmdError>
[src]

Find an element on the page.

pub fn find_all(
    &mut self,
    search: Locator
) -> impl Future<Item = Vec<Element>, Error = CmdError>
[src]

Find elements on the page.

pub fn wait_for<F, FF>(
    self,
    is_ready: F
) -> impl Future<Item = Self, Error = CmdError> where
    F: FnMut(&mut Client) -> FF,
    FF: IntoFuture<Item = bool, Error = CmdError>, 
[src]

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(
    self,
    search: Locator
) -> impl Future<Item = Element, Error = CmdError>
[src]

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 fn wait_for_navigation(
    self,
    current: Option<Url>
) -> impl Future<Item = Self, Error = CmdError>
[src]

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(
    &mut self,
    search: Locator
) -> impl Future<Item = Form, Error = CmdError>
[src]

Locate a form on the page.

Through the returned Form, HTML forms can be filled out and submitted.

Trait Implementations

impl Clone for Client[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Client

impl Sync for Client

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Erased for T