[][src]Struct thirtyfour::sync::WebDriver

pub struct WebDriver { /* fields omitted */ }

This WebDriver struct encapsulates a synchronous Selenium WebDriver browser session. For the async driver, see WebDriver.

Example:

use thirtyfour::error::WebDriverResult;
use thirtyfour::{DesiredCapabilities, sync::WebDriver};

fn main() -> WebDriverResult<()> {
    let caps = DesiredCapabilities::chrome();
    let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;
    driver.get("http://webappdemo")?;
    Ok(())
}

Methods

impl WebDriver[src]

pub fn new<T>(
    remote_server_addr: &str,
    capabilities: T
) -> WebDriverResult<Self> where
    T: Serialize
[src]

Create a new synchronous WebDriver struct.

Example

let caps = DesiredCapabilities::chrome();
let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)
    .expect("Error starting browser");

pub fn capabilities(&self) -> DesiredCapabilities[src]

Return a clone of the capabilities as returned by Selenium.

pub fn close(&self) -> WebDriverResult<()>[src]

Close the current window.

pub fn quit(&self) -> WebDriverResult<()>[src]

End the webdriver session.

pub fn get<S: Into<String>>(&self, url: S) -> WebDriverResult<()>[src]

Navigate to the specified URL.

pub fn current_url(&self) -> WebDriverResult<String>[src]

Get the current URL as a String.

pub fn page_source(&self) -> WebDriverResult<String>[src]

Get the page source as a String.

pub fn title(&self) -> WebDriverResult<String>[src]

Get the page title as a String.

pub fn find_element(&self, by: By) -> WebDriverResult<WebElement>[src]

Search for an element on the current page using the specified selector.

Example:

let elem_text = driver.find_element(By::Name("input1"))?;
let elem_button = driver.find_element(By::Id("button-set"))?;
let elem_result = driver.find_element(By::Name("input-result"))?;

pub fn find_elements(&self, by: By) -> WebDriverResult<Vec<WebElement>>[src]

Search for all elements on the current page that match the specified selector.

Example:

let elems = driver.find_elements(By::ClassName("section"))?;
for elem in elems {
    assert!(elem.get_attribute("class")?.contains("section"));
}

pub fn execute_script(
    &self,
    script: &str,
    args: &ScriptArgs
) -> WebDriverResult<ScriptRetSync>
[src]

Execute the specified Javascript synchronously and return the result.

Example:

use thirtyfour::ScriptArgs;
let elem = driver.find_element(By::Id("button1"))?;
let mut args = ScriptArgs::new();
args.push(elem.clone())?;
args.push("TESTING")?;
let ret = driver.execute_script(r#"
    arguments[0].innerHTML = arguments[1];
    return arguments[0];
    "#, &args
)?;
let elem_out = ret.get_element()?;
assert_eq!(elem_out.element_id, elem.element_id);
assert_eq!(elem_out.text()?, "TESTING");

pub fn execute_async_script(
    &self,
    script: &str,
    args: &ScriptArgs
) -> WebDriverResult<ScriptRetSync>
[src]

Execute the specified Javascrypt asynchronously and return the result.

Example:

use thirtyfour::ScriptArgs;
let elem = driver.find_element(By::Id("button1"))?;
let mut args = ScriptArgs::new();
args.push(elem.clone())?;
args.push("TESTING")?;
let ret = driver.execute_async_script(r#"
    // Selenium automatically provides an extra argument which is a
    // function that receives the return value(s).
    let done = arguments[2];
    window.setTimeout(() => {
        arguments[0].innerHTML = arguments[1];
        done(arguments[0]);
    }, 1000);
    "#, &args
)?;
let elem_out = ret.get_element()?;
assert_eq!(elem_out.element_id, elem.element_id);
assert_eq!(elem_out.text()?, "TESTING");

pub fn current_window_handle(&self) -> WebDriverResult<WindowHandle>[src]

Get the current window handle.

pub fn window_handles(&self) -> WebDriverResult<Vec<WindowHandle>>[src]

Get all window handles for the current session.

pub fn maximize_window(&self) -> WebDriverResult<()>[src]

Maximize the current window.

Example:

driver.maximize_window()?;

pub fn minimize_window(&self) -> WebDriverResult<()>[src]

Minimize the current window.

pub fn fullscreen_window(&self) -> WebDriverResult<()>[src]

Make the current window fullscreen.

Example:

driver.fullscreen_window()?;

pub fn get_window_rect(&self) -> WebDriverResult<Rect>[src]

Get the current window rectangle, in pixels.

The returned Rect struct has members x, y, width, height, all i32.

pub fn set_window_rect(&self, rect: OptionRect) -> WebDriverResult<()>[src]

Set the current window rectangle, in pixels.

This requires an OptionRect, which is similar to Rect except all members are wrapped in Option.

Example:

use thirtyfour::OptionRect;
let r = OptionRect::new().with_size(1280, 720);
driver.set_window_rect(r)?;

You can also convert from a Rect if you want to get the window size and modify it before setting it again.

use thirtyfour::OptionRect;
let rect = driver.get_window_rect()?;
let option_rect = OptionRect::from(rect);
driver.set_window_rect(option_rect.with_width(1024))?;

pub fn back(&self) -> WebDriverResult<()>[src]

Go back. This is equivalent to clicking the browser's back button.

Example:

driver.back()?;

pub fn forward(&self) -> WebDriverResult<()>[src]

Go forward. This is equivalent to clicking the browser's forward button.

Example:

driver.forward()?;

pub fn refresh(&self) -> WebDriverResult<()>[src]

Refresh the current page.

Example:

driver.refresh()?;

pub fn get_timeouts(&self) -> WebDriverResult<TimeoutConfiguration>[src]

Get all timeouts for the current session.

Example:

use thirtyfour::TimeoutConfiguration;
use std::time::Duration;

let timeouts = driver.get_timeouts()?;
println!("Page load timeout = {:?}", timeouts.page_load());

pub fn set_timeouts(
    &self,
    timeouts: TimeoutConfiguration
) -> WebDriverResult<()>
[src]

Set all timeouts for the current session.

Example:

use thirtyfour::TimeoutConfiguration;
use std::time::Duration;

// Setting timeouts to None means those timeout values will not be updated.
let timeouts = TimeoutConfiguration::new(None, Some(Duration::new(11, 0)), None);
driver.set_timeouts(timeouts.clone())?;

pub fn implicitly_wait(&self, time_to_wait: Duration) -> WebDriverResult<()>[src]

Set the implicit wait timeout.

pub fn set_script_timeout(&self, time_to_wait: Duration) -> WebDriverResult<()>[src]

Set the script timeout.

pub fn set_page_load_timeout(
    &self,
    time_to_wait: Duration
) -> WebDriverResult<()>
[src]

Set the page load timeout.

pub fn action_chain(&self) -> ActionChain[src]

Create a new action chain for this session.

Example:

let elem_text = driver.find_element(By::Name("input1"))?;
let elem_button = driver.find_element(By::Id("button-set"))?;

driver.action_chain()
    .send_keys_to_element(&elem_text, "thirtyfour")
    .move_to_element_center(&elem_button)
    .click()
    .perform()?;

pub fn get_cookies(&self) -> WebDriverResult<Vec<Cookie>>[src]

Get all cookies.

Example:

let cookies = driver.get_cookies()?;
for cookie in &cookies {
    println!("Got cookie: {}", cookie.value());
}

Get the specified cookie.

Example:

let cookie = driver.get_cookie("key")?;
println!("Got cookie: {}", cookie.value());

Delete the specified cookie.

Example:

driver.delete_cookie("key")?;

pub fn delete_all_cookies(&self) -> WebDriverResult<()>[src]

Delete all cookies.

Example:

driver.delete_all_cookies()?;

Add the specified cookie.

Example:

let cookie = Cookie::new("key", serde_json::json!("value"));
driver.add_cookie(cookie)?;

pub fn screenshot_as_base64(&self) -> WebDriverResult<String>[src]

Take a screenshot of the current window and return it as a base64-encoded String.

pub fn screenshot_as_png(&self) -> WebDriverResult<Vec<u8>>[src]

Take a screenshot of the current window and return it as PNG bytes.

pub fn screenshot(&self, path: &Path) -> WebDriverResult<()>[src]

Take a screenshot of the current window and write it to the specified filename.

pub fn switch_to(&self) -> SwitchTo[src]

Return a SwitchTo struct for switching to another window or frame.

Trait Implementations

impl Clone for WebDriver[src]

impl Debug for WebDriver[src]

impl Drop for WebDriver[src]

fn drop(&mut self)[src]

Close the current session when the WebDriver struct goes out of scope.

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.