[−][src]Struct thirtyfour::WebDriver
The WebDriver struct encapsulates an async Selenium WebDriver browser session. For the sync driver, see sync::WebDriver.
Example:
use thirtyfour::error::WebDriverResult; use thirtyfour::{DesiredCapabilities, WebDriver}; use tokio; #[tokio::main] async fn main() -> WebDriverResult<()> { let caps = DesiredCapabilities::chrome(); let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps).await?; driver.get("http://webappdemo").await?; Ok(()) }
Methods
impl WebDriver
[src]
pub async fn new<'_, '_>(
remote_server_addr: &'_ str,
capabilities: &'_ DesiredCapabilities
) -> WebDriverResult<Self>
[src]
remote_server_addr: &'_ str,
capabilities: &'_ DesiredCapabilities
) -> WebDriverResult<Self>
Create a new async WebDriver struct.
Example
let caps = DesiredCapabilities::chrome(); let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps).await?;
pub fn capabilities(&self) -> &Value
[src]
Return the actual capabilities as returned by Selenium.
pub async fn close<'_>(&'_ self) -> WebDriverResult<()>
[src]
Close the current window.
pub async fn quit<'_>(&'_ self) -> WebDriverResult<()>
[src]
End the webdriver session.
pub async fn get<'_, S: Into<String>>(&'_ self, url: S) -> WebDriverResult<()>
[src]
Navigate to the specified URL.
pub async fn current_url<'_>(&'_ self) -> WebDriverResult<String>
[src]
Get the current URL as a String.
pub async fn page_source<'_>(&'_ self) -> WebDriverResult<String>
[src]
Get the page source as a String.
pub async fn title<'_>(&'_ self) -> WebDriverResult<String>
[src]
Get the page title as a String.
pub async fn find_element<'_, '_>(
&'_ self,
by: By<'_>
) -> WebDriverResult<WebElement>
[src]
&'_ self,
by: By<'_>
) -> WebDriverResult<WebElement>
Search for an element on the current page using the specified selector.
Example:
let elem_text = driver.find_element(By::Name("input1")).await?; let elem_button = driver.find_element(By::Id("button-set")).await?; let elem_result = driver.find_element(By::Name("input-result")).await?;
pub async fn find_elements<'_, '_>(
&'_ self,
by: By<'_>
) -> WebDriverResult<Vec<WebElement>>
[src]
&'_ self,
by: By<'_>
) -> WebDriverResult<Vec<WebElement>>
Search for all elements on the current page that match the specified selector.
Example:
let elems = driver.find_elements(By::ClassName("section")).await?; for elem in elems { assert!(elem.get_attribute("class").await?.contains("section")); }
pub async fn execute_script<'_, '_, '_>(
&'_ self,
script: &'_ str,
args: &'_ ScriptArgs
) -> WebDriverResult<ScriptRet>
[src]
&'_ self,
script: &'_ str,
args: &'_ ScriptArgs
) -> WebDriverResult<ScriptRet>
Execute the specified Javascript synchronously and return the result.
Example:
use thirtyfour::ScriptArgs; let elem = driver.find_element(By::Id("button1")).await?; 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 ).await?; let elem_out = ret.get_element()?; assert_eq!(elem_out.element_id, elem.element_id); assert_eq!(elem_out.text().await?, "TESTING");
pub async fn execute_async_script<'_, '_, '_>(
&'_ self,
script: &'_ str,
args: &'_ ScriptArgs
) -> WebDriverResult<ScriptRet>
[src]
&'_ self,
script: &'_ str,
args: &'_ ScriptArgs
) -> WebDriverResult<ScriptRet>
Execute the specified Javascrypt asynchronously and return the result.
Example:
use thirtyfour::ScriptArgs; let elem = driver.find_element(By::Id("button1")).await?; 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 ).await?; let elem_out = ret.get_element()?; assert_eq!(elem_out.element_id, elem.element_id); assert_eq!(elem_out.text().await?, "TESTING");
pub async fn current_window_handle<'_>(
&'_ self
) -> WebDriverResult<WindowHandle>
[src]
&'_ self
) -> WebDriverResult<WindowHandle>
Get the current window handle.
pub async fn window_handles<'_>(&'_ self) -> WebDriverResult<Vec<WindowHandle>>
[src]
Get all window handles for the current session.
pub async fn maximize_window<'_>(&'_ self) -> WebDriverResult<()>
[src]
pub async fn minimize_window<'_>(&'_ self) -> WebDriverResult<()>
[src]
Minimize the current window.
pub async fn fullscreen_window<'_>(&'_ self) -> WebDriverResult<()>
[src]
pub async 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 async fn set_window_rect<'_>(
&'_ self,
rect: OptionRect
) -> WebDriverResult<()>
[src]
&'_ self,
rect: OptionRect
) -> WebDriverResult<()>
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).await?;
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().await?; let option_rect = OptionRect::from(rect); driver.set_window_rect(option_rect.with_width(1024)).await?;
pub async fn back<'_>(&'_ self) -> WebDriverResult<()>
[src]
pub async fn forward<'_>(&'_ self) -> WebDriverResult<()>
[src]
Go forward. This is equivalent to clicking the browser's forward button.
Example:
driver.forward().await?;
pub async fn refresh<'_>(&'_ self) -> WebDriverResult<()>
[src]
pub async 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().await?; println!("Page load timeout = {:?}", timeouts.page_load());
pub async fn set_timeouts<'_>(
&'_ self,
timeouts: TimeoutConfiguration
) -> WebDriverResult<()>
[src]
&'_ self,
timeouts: TimeoutConfiguration
) -> WebDriverResult<()>
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()).await?;
pub async fn implicitly_wait<'_>(
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
[src]
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
Set the implicit wait timeout.
pub async fn set_script_timeout<'_>(
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
[src]
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
Set the script timeout.
pub async fn set_page_load_timeout<'_>(
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
[src]
&'_ self,
time_to_wait: Duration
) -> WebDriverResult<()>
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")).await?; let elem_button = driver.find_element(By::Id("button-set")).await?; driver.action_chain() .send_keys_to_element(&elem_text, "thirtyfour") .move_to_element_center(&elem_button) .click() .perform().await?;
pub async fn get_cookies<'_>(&'_ self) -> WebDriverResult<Vec<Cookie>>
[src]
Get all cookies.
Example:
let cookies = driver.get_cookies().await?; for cookie in &cookies { println!("Got cookie: {}", cookie.value()); }
pub async fn get_cookie<'_, '_>(
&'_ self,
name: &'_ str
) -> WebDriverResult<Cookie>
[src]
&'_ self,
name: &'_ str
) -> WebDriverResult<Cookie>
Get the specified cookie.
Example:
let cookie = driver.get_cookie("key").await?; println!("Got cookie: {}", cookie.value());
pub async fn delete_cookie<'_, '_>(
&'_ self,
name: &'_ str
) -> WebDriverResult<()>
[src]
&'_ self,
name: &'_ str
) -> WebDriverResult<()>
pub async fn delete_all_cookies<'_>(&'_ self) -> WebDriverResult<()>
[src]
pub async fn add_cookie<'_>(&'_ self, cookie: Cookie) -> WebDriverResult<()>
[src]
Add the specified cookie.
Example:
use thirtyfour::Cookie; let cookie = Cookie::new("key", serde_json::json!("value")); driver.add_cookie(cookie).await?;
pub async fn screenshot_as_base64<'_>(&'_ self) -> WebDriverResult<String>
[src]
Take a screenshot of the current window and return it as a base64-encoded String.
pub async fn screenshot_as_png<'_>(&'_ self) -> WebDriverResult<Vec<u8>>
[src]
Take a screenshot of the current window and return it as PNG bytes.
pub async 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
Auto Trait Implementations
impl !RefUnwindSafe for WebDriver
impl Send for WebDriver
impl Sync for WebDriver
impl Unpin for WebDriver
impl !UnwindSafe for WebDriver
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> 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>,