### Example Usage: Get Google Title in New Tab (Rust) Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This example demonstrates how to use the `in_new_tab` method to open a new tab, navigate to Google, retrieve the page title, and assert its value. It requires setting up a WebDriver instance and running within an async context. ```rust # use thirtyfour::prelude::*; # use thirtyfour::support::block_on; # # fn main() -> WebDriverResult<()> { # block_on(async { # let caps = DesiredCapabilities::chrome(); # let driver = WebDriver::new("http://localhost:4444", caps).await?; let window_title = driver.in_new_tab(|| async { driver.goto("https://www.google.com").await?; driver.title().await }).await?; assert_eq!(window_title, "Google"); # driver.quit().await?; # Ok(()) # }) # } ``` -------------------------------- ### Rust Example Searches Source: https://docs.rs/thirtyfour/latest/thirtyfour/extensions/query/enum.ElementQueryWaitOptions_search= Provides examples of search queries that might be used in conjunction with type erasure or generic programming in Rust. These examples illustrate common patterns for searching types and their associated functions. ```rust // Example searches: // * std::vec // * u32 -> bool // * Option, (T -> U) -> Option ``` -------------------------------- ### Install Firefox Add-on Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/addons/firefox/firefoxtools.rs Installs a Firefox add-on from a given path. The `temporary` parameter can be set to `Some(true)` to install the add-on only for the current session. ```rust pub async fn install_addon(&self, path: &str, temporary: Option) -> WebDriverResult<()> { self.handle .cmd(FirefoxCommand::InstallAddon { path: path.to_string(), temporary, }) .await?; Ok(()) } ``` -------------------------------- ### GET /source Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs Retrieves the entire HTML source code of the current page. ```APIDOC ## GET /source ### Description Retrieves the entire HTML source code of the current page. ### Method GET ### Endpoint /session/{sessionId}/source ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the current session. ### Response #### Success Response (200) - **status** (integer) - The status of the operation (0 for success). - **value** (string) - The HTML source code of the page. #### Response Example ```json { "status": 0, "value": "Example Page

Hello

" } ``` ``` -------------------------------- ### Example Usage of ElementWaiter - Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/query/element_waiter.rs Demonstrates how to use the ElementWaiter to wait for an element to be displayed. This example shows the typical workflow of finding an element and then applying a wait condition to it. ```rust # use thirtyfour::prelude::*; # use thirtyfour::support::block_on; # # fn main() -> WebDriverResult<()> { # block_on(async { # let caps = DesiredCapabilities::chrome(); # let mut driver = WebDriver::new("http://localhost:4444", caps).await?; let elem = driver.query(By::Id("button1")).first().await?; // Wait until the element is displayed. elem.wait_until().displayed().await?; # driver.quit().await?; # Ok(()) # }) # } ``` -------------------------------- ### Element Query Example Usage (Rust) Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/query/element_query.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates high-level element querying using the builder pattern in Rust. This example shows how to use `WebDriver::query()` and `WebElement::query()` to find elements on a webpage, with chaining for selecting specific elements. ```rust /// High-level interface for performing powerful element queries using a /// builder pattern. /// /// # Example: /// ```no_run /// # use thirtyfour::prelude::*; /// # use thirtyfour::support::block_on; /// # /// # fn main() -> WebDriverResult<()> { /// # block_on(async { /// # let caps = DesiredCapabilities::chrome(); /// # let mut driver = WebDriver::new("http://localhost:4444", caps).await?; /// # driver.goto("http://localhost:8000").await?; /// // WebDriver::query() example. /// let elem = driver.query(By::Css("div[data-section='section-buttons']")).first().await?; /// // WebElement::query() example. /// let elem_button = elem.query(By::Id("button1")).first().await?; /// # assert_eq!(elem_button.tag_name().await?, "button"); /// # driver.quit().await?; /// # Ok(()) /// # }) /// # } /// ``` #[derive(Debug)] pub struct ElementQuery { source: ElementQuerySource, poller: Arc, selectors: Vec, options: ElementQueryOptions, } ``` -------------------------------- ### ElementQuery Example Usage Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/query/element_query.rs_search=u32+-%3E+bool Demonstrates how to use the ElementQuery to find elements on a webpage. It shows examples of querying elements using WebDriver and WebElement, including finding a button by its ID. ```rust # use thirtyfour::prelude::*; # use thirtyfour::support::block_on; # # fn main() -> WebDriverResult<()> { # block_on(async { # let caps = DesiredCapabilities::chrome(); # let mut driver = WebDriver::new("http://localhost:4444", caps).await?; # driver.goto("http://localhost:8000").await?; # // WebDriver::query() example. # let elem = driver.query(By::Css("div[data-section='section-buttons']")).first().await?; # // WebElement::query() example. # let elem_button = elem.query(By::Id("button1")).first().await?; # # assert_eq!(elem_button.tag_name().await?, "button"); # # driver.quit().await?; # # Ok(()) # # }) # # } ``` -------------------------------- ### GET /title Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs Retrieves the title of the current page. ```APIDOC ## GET /title ### Description Retrieves the title of the current page. ### Method GET ### Endpoint /session/{sessionId}/title ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the current session. ### Response #### Success Response (200) - **status** (integer) - The status of the operation (0 for success). - **value** (string) - The title of the page. #### Response Example ```json { "status": 0, "value": "Example Domain" } ``` ``` -------------------------------- ### ElementQuery Builder Pattern Example (Rust) Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/query/element_query.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates the builder pattern for ElementQuery in Rust, showing how to chain methods to configure and execute element queries. This example includes setting options and providing descriptions for more context in error messages. ```rust impl ElementQuery { /// Create a new `ElementQuery`. /// /// See `WebDriver::query()` or `WebElement::query()` rather than instantiating /// this directly. pub fn new( source: ElementQuerySource, by: By, poller: Arc, ) -> Self { let selector = ElementSelector::new(by); Self { source, poller, selectors: vec![selector], options: ElementQueryOptions::default(), } } /// Provide the options to use with this query. pub fn options(mut self, options: ElementQueryOptions) -> Self { self.options = options; // Apply wait options. match self.options.wait { None | Some(ElementQueryWaitOptions::WaitDefault) => self, Some(ElementQueryWaitOptions::Wait { timeout, interval, }) => self.wait(timeout, interval), Some(ElementQueryWaitOptions::NoWait) => self.nowait(), } } /// Provide a name that will be included in the error message if the query was not successful. /// This is useful for providing more context about this particular query. pub fn desc(mut self, description: &str) -> Self { self.options = self.options.description(description); self } } ``` -------------------------------- ### Example: Create and Use WebDriver Session Source: https://docs.rs/thirtyfour/latest/thirtyfour/struct.WebDriver_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create a new WebDriver session using desired capabilities (e.g., Firefox), navigate to a URL, and then quit the session. It assumes a WebDriver-compatible server is running locally. ```rust use thirtyfour::prelude::*; let caps = DesiredCapabilities::firefox(); // NOTE: this assumes you have a WebDriver compatible server running // at http://localhost:4444 // e.g. `geckodriver -p 4444` // NOTE: If using selenium 3.x, use "http://localhost:4444/wd/hub/session" for the url. let driver = WebDriver::new("http://localhost:4444", caps).await?; driver.goto("https://www.rust-lang.org/").await?; // Always remember to close the session. driver.quit().await?; ``` -------------------------------- ### Get WebElement Attribute in Rust Source: https://docs.rs/thirtyfour/latest/thirtyfour/struct.WebElement_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the value of a specified attribute of a `WebElement`. Returns `None` if the attribute does not exist. Example shows getting the 'name' attribute. ```rust let elem = driver.find(By::Name("input2")).await?; let attribute: Option = elem.attr("name").await?; assert_eq!(attribute.unwrap(), "input2"); // If the attribute does not exist, None is returned. assert_eq!(elem.attr("invalid-attribute").await?, None); ``` -------------------------------- ### POST /get Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs Alias for the goto() method, navigates the browser to a specified URL. ```APIDOC ## POST /get ### Description Alias for the goto() method, navigates the browser to a specified URL. ### Method POST ### Endpoint /session/{sessionId}/url ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the current session. #### Request Body - **url** (string) - Required - The URL to navigate to. ### Request Example ```json { "url": "https://www.rust-lang.org" } ``` ### Response #### Success Response (200) - **status** (integer) - The status of the operation (0 for success). - **value** (any) - An empty object, as the response is typically null. #### Response Example ```json { "status": 0, "value": null } ``` ``` -------------------------------- ### Get WebElement Property in Rust Source: https://docs.rs/thirtyfour/latest/thirtyfour/struct.WebElement_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the value of a specified property of a `WebElement`. Returns `None` if the property does not exist. Example shows getting the 'checked' property of a checkbox. ```rust let elem = driver.find(By::Css("input[type='checkbox']")).await?; let property_value: Option = elem.prop("checked").await?; assert_eq!(property_value.unwrap(), "true"); // If a property is not found, None is returned. assert_eq!(elem.prop("invalid-property").await?, None); ``` -------------------------------- ### Sending Commands and Getting Status with SessionHandle Source: https://docs.rs/thirtyfour/latest/thirtyfour/session/handle/struct.SessionHandle_search=u32+-%3E+bool Illustrates sending custom commands to the WebDriver server and retrieving the server's status using SessionHandle. The status example shows how to initialize a driver and then get its status. ```rust // Send a command to the webdriver server. let response = driver.cmd(command_data).await?; // Get the WebDriver status. let caps = DesiredCapabilities::chrome(); let mut driver = WebDriver::new("http://localhost:4444", caps).await?; let status = driver.status().await?; ``` -------------------------------- ### Automated Website UI Testing with Rust WebDriver Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/lib.rs_search= This example demonstrates basic website UI testing using the Thirtyfour Rust library. It shows how to initialize a WebDriver session, navigate to a URL, find elements, input text, click buttons, and verify page titles. It also highlights the importance of explicitly quitting the WebDriver session to avoid blocking the async executor. ```rust use thirtyfour::prelude::*; #[tokio::main] async fn main() -> WebDriverResult<()> { let caps = DesiredCapabilities::chrome(); let driver = WebDriver::new("http://localhost:9515", caps).await?; // Navigate to https://wikipedia.org. driver.goto("https://wikipedia.org").await?; let elem_form = driver.find(By::Id("search-form")).await?; // Find element from element. let elem_text = elem_form.find(By::Id("searchInput")).await?; // Type in the search terms. elem_text.send_keys("selenium").await?; // Click the search button. let elem_button = elem_form.find(By::Css("button[type='submit']")).await?; elem_button.click().await?; // Look for header to implicitly wait for the page to load. driver.find(By::ClassName("firstHeading")).await?; assert_eq!(driver.title().await?, "Selenium - Wikipedia"); // explicitly close the browser. driver.quit().await?; Ok(()) } ``` -------------------------------- ### POST /goto Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs Navigates the browser to a specified URL. It can handle relative URLs by prepending 'https://'. ```APIDOC ## POST /goto ### Description Navigates the browser to a specified URL. It can handle relative URLs by prepending 'https://'. ### Method POST ### Endpoint /session/{sessionId}/url ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the current session. #### Request Body - **url** (string) - Required - The URL to navigate to. ### Request Example ```json { "url": "https://www.rust-lang.org" } ``` ### Response #### Success Response (200) - **status** (integer) - The status of the operation (0 for success). - **value** (any) - An empty object, as the response is typically null. #### Response Example ```json { "status": 0, "value": null } ``` ``` -------------------------------- ### Get WebElement Property in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/web_element.rs Retrieves the value of a specified property of a web element. It returns an Option within a WebDriverResult, where None indicates the property was not found. The example shows how to get the 'checked' property of a checkbox. ```rust pub async fn prop(&self, name: impl IntoArcStr) -> WebDriverResult> { let resp = self .handle .cmd(Command::GetElementProperty(self.element_id.clone(), name.into())) .await?; match resp.value()? { Value::String(v) => Ok(Some(v)), Value::Bool(b) => Ok(Some(b.to_string())), Value::Null => Ok(None), v => Err(WebDriverError::Json(format!("Unexpected value for property: {:?}", v))), } } ``` -------------------------------- ### WebDriver Initialization and Usage Source: https://docs.rs/thirtyfour/latest/thirtyfour/struct.WebDriver_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create a new WebDriver instance, navigate to a URL, and properly close the session. ```APIDOC ## POST /session ### Description Creates a new WebDriver session. This is the primary method for initiating a browser automation session. ### Method POST ### Endpoint `/session` ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the WebDriver server (e.g., http://localhost:4444). - **capabilities** (object) - Required - An object specifying the desired browser capabilities (e.g., browser name, version, platform). ### Request Body (Not applicable for this endpoint, capabilities are passed as query parameters or implicitly handled) ### Request Example ```rust use thirtyfour::prelude::*; async fn example() -> WebDriverResult<()> { let caps = DesiredCapabilities::firefox(); // NOTE: this assumes you have a WebDriver compatible server running // at http://localhost:4444 // e.g. `geckodriver -p 4444` // NOTE: If using selenium 3.x, use "http://localhost:4444/wd/hub/session" for the url. let driver = WebDriver::new("http://localhost:4444", caps).await?; driver.goto("https://www.rust-lang.org/").await?; // Always remember to close the session. driver.quit().await?; Ok(()) } ``` ### Response #### Success Response (200) - **WebDriver** (object) - An instance of the WebDriver struct representing the active session. #### Response Example (WebDriver instance is returned implicitly by the `new` function) ### Notes - For Selenium 3.x, append `/wd/hub/session` to the server URL. - For Selenium 4.x and later, the base URL is sufficient. - Ensure the WebDriver server (e.g., geckodriver, chromedriver) is running and accessible at the specified URL. ``` -------------------------------- ### Get Metadata of Paths with Rust Result Source: https://docs.rs/thirtyfour/latest/thirtyfour/error/type.WebDriverResult_search=std%3A%3Avec Shows how to use Rust's Result type with `Path::metadata` to get file metadata, handling potential errors like 'NotFound'. This example illustrates checking for success or failure of file system operations. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### POST /session/{session_id}/window/new Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=std%3A%3Avec Creates a new browser window or tab. ```APIDOC ## POST /session/{session_id}/window/new ### Description Creates a new browser window or tab. ### Method POST ### Endpoint /session/{session_id}/window/new ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the browser session. #### Request Body - **type** (string) - Required - The type of window to create. Can be 'window' or 'tab'. ### Request Example (New Window) ```json { "type": "window" } ``` ### Request Example (New Tab) ```json { "type": "tab" } ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the operation. - **value** (string) - The handle of the newly created window or tab. #### Response Example ```json { "status": 0, "value": "new-window-handle" } ``` ``` -------------------------------- ### Set Firefox Binary Path - Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/capabilities/firefox.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Specifies the command to start the Firefox binary. This is useful when Firefox is installed in a non-standard location or when using a custom build. ```rust pub fn set_firefox_binary(&mut self, start_cmd: &str) -> WebDriverResult<()> { self.insert_browser_option("binary", start_cmd) } ``` -------------------------------- ### Basic WebDriver Usage in Rust Source: https://docs.rs/thirtyfour/latest/index Demonstrates the fundamental usage of the thirtyfour library to automate browser interactions. This example shows how to initialize a WebDriver instance, navigate to a URL, find elements by various selectors, send keys, click elements, and close the browser session. It requires a running WebDriver instance (e.g., chromedriver) and a compatible browser. ```rust use thirtyfour::prelude::*; #[tokio::main] async fn main() -> WebDriverResult<()> { let caps = DesiredCapabilities::chrome(); let driver = WebDriver::new("http://localhost:9515", caps).await?; // Navigate to https://wikipedia.org. driver.goto("https://wikipedia.org").await?; let elem_form = driver.find(By::Id("search-form")).await?; // Find element from element. let elem_text = elem_form.find(By::Id("searchInput")).await?; // Type in the search terms. elem_text.send_keys("selenium").await?; // Click the search button. let elem_button = elem_form.find(By::Css("button[type='submit']")).await?; elem_button.click().await?; // Look for header to implicitly wait for the page to load. driver.find(By::ClassName("firstHeading")).await?; assert_eq!(driver.title().await?, "Selenium - Wikipedia"); // explicitly close the browser. driver.quit().await?; Ok(()) } ``` -------------------------------- ### Casting Functionality Source: https://docs.rs/thirtyfour/latest/thirtyfour/extensions/cdp/struct.ChromeDevTools_search=std%3A%3Avec Provides methods for managing casting sessions, including getting available sinks, setting the sink to use, starting tab mirroring, and stopping casting. ```rust use thirtyfour::extensions::cdp::ChromeDevTools; let dev_tools = ChromeDevTools::new(driver.handle.clone()); // Get available sinks let sinks = dev_tools.get_sinks().await?; // Set sink to use (replace "MySinkName" with an actual sink name) // dev_tools.set_sink_to_use("MySinkName").await?; // Start tab mirroring (replace "MySinkName" with an actual sink name) // dev_tools.start_tab_mirroring("MySinkName").await?; // Stop casting (replace "MySinkName" with an actual sink name) // dev_tools.stop_casting("MySinkName").await?; ``` -------------------------------- ### ElementQuery Construction and Configuration Methods Source: https://docs.rs/thirtyfour/latest/thirtyfour/extensions/query/struct.ElementQuery_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to construct and configure an ElementQuery. Covers methods for setting source, selector, options, description, error handling, and polling behavior. ```rust pub fn new( source: ElementQuerySource, by: By, poller: Arc, ) -> Self pub fn options(self, options: ElementQueryOptions) -> Self pub fn desc(self, description: &str) -> Self pub fn ignore_errors(self, ignore: bool) -> Self pub fn with_poller( self, poller: Arc, ) -> Self pub fn wait(self, timeout: Duration, interval: Duration) -> Self pub fn nowait(self) -> Self pub fn or(self, by: By) -> Self ``` -------------------------------- ### Cast Tab Mirroring Control Source: https://docs.rs/thirtyfour/latest/thirtyfour/extensions/cdp/struct.ChromeDevTools_search= Provides examples for controlling tab mirroring sessions using ChromeDevTools, including starting and stopping mirroring, and setting the target sink. ```rust use thirtyfour::extensions::cdp::ChromeDevTools; let dev_tools = ChromeDevTools::new(driver.handle.clone()); let sink_name = "My Cast Receiver"; // Start tab mirroring dev_tools.start_tab_mirroring(sink_name).await?; // Stop casting dev_tools.stop_casting(sink_name).await?; // Set sink to use dev_tools.set_sink_to_use(sink_name).await?; ``` -------------------------------- ### Get WebDriver Status in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search= Retrieves the current status of the WebDriver server. This function sends a 'Status' command and expects a `WebDriverStatus` object in return. It includes an example demonstrating its usage within an async block. ```rust pub async fn status(&self) -> WebDriverResult { self.cmd(Command::Status).await?.value() } ``` -------------------------------- ### POST /print Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs Prints the current window to a PDF document. The PDF is returned as base64 encoded string. ```APIDOC ## POST /print ### Description Prints the current window to a PDF document. The PDF is returned as base64 encoded string. ### Method POST ### Endpoint /session/{session id}/print ### Parameters #### Request Body - **parameters** (object) - Optional - Parameters for printing the page. - **orientation** (string) - Optional - "portrait" or "landscape". - **scale** (number) - Optional - Scale of the print documentation. - **clip** (object) - Optional - The clip command for the page. - **x** (number) - Required - X coordinate. - **y** (number) - Required - Y coordinate. - **width** (number) - Required - Width. - **height** (number) - Required - Height. - **pageRanges** (array) - Optional - Array of page numbers to print. - **ignoreInvalidPageRanges** (boolean) - Optional - Whether to ignore invalid page ranges. - **displayHeaderFooter** (boolean) - Optional - Whether to display header and footer. - **headerTemplate** (string) - Optional - HTML template for the header. - **footerTemplate** (string) - Optional - HTML template for the footer. - **printBackground** (boolean) - Optional - Whether to print the background graphics. - **paperWidth** (number) - Optional - Width of the paper. - **paperHeight** (number) - Optional - Height of the paper. - **marginTop** (number) - Optional - Top margin. - **marginBottom** (number) - Optional - Bottom margin. - **marginLeft** (number) - Optional - Left margin. - **marginRight** (number) - Optional - Right margin. - **pageRanges** (array) - Optional - Array of page numbers to print. ### Request Example ```json { "parameters": { "orientation": "portrait", "scale": 0.8, "printBackground": true } } ``` ### Response #### Success Response (200) - **value** (string) - Base64 encoded PDF string. #### Response Example ```json { "value": "JVBERi0xLjQKJe..." } ``` ``` -------------------------------- ### Get WebElement Attribute in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/web_element.rs Fetches the value of a specified attribute for a web element. It returns an Option within a WebDriverResult, returning None if the attribute doesn't exist. The example demonstrates retrieving the 'name' attribute. ```rust pub async fn attr(&self, name: impl IntoArcStr) -> WebDriverResult> { self .handle .cmd(Command::GetElementAttribute(self.element_id.clone(), name.into())) .await? .value() } ``` -------------------------------- ### Get All Cookies in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search= Retrieves all cookies associated with the current browser session. The function returns a `WebDriverResult` containing a `Vec`. The example demonstrates iterating through the retrieved cookies and printing their values. This function requires an active WebDriver session. ```rust /// Get all cookies. /// /// # Example: /// ```no_run /// # use thirtyfour::prelude::*; /// # use thirtyfour::support::block_on; /// # /// # fn main() -> WebDriverResult<()> { /// # block_on(async { /// # let caps = DesiredCapabilities::chrome(); /// # let driver = WebDriver::new("http://localhost:4444", caps).await?; /// let cookies = driver.get_all_cookies().await?; /// for cookie in &cookies { /// println!("Got cookie: {}", cookie.value); /// } /// # driver.quit().await?; /// # Ok(()) /// # }) /// # } /// ``` pub async fn get_all_cookies(&self) -> WebDriverResult> { self.cmd(Command::GetAllCookies).await?.value() } ``` -------------------------------- ### Initialize WebDriverConfigBuilder Source: https://docs.rs/thirtyfour/latest/thirtyfour/common/config/struct.WebDriverConfigBuilder_search= Creates a new instance of WebDriverConfigBuilder to start configuring WebDriver settings. This is the entry point for building a WebDriverConfig. ```rust pub struct WebDriverConfigBuilder { /* private fields */ } impl WebDriverConfigBuilder { /// Create a new `WebDriverConfigBuilder`. pub fn new() -> Self; } ``` -------------------------------- ### POST /window/fullscreen Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search= Makes the current browser window fullscreen. ```APIDOC ## POST /window/fullscreen ### Description Make the current window fullscreen. ### Method POST ### Endpoint /session/{sessionid}/window/fullscreen ### Parameters None ### Request Example None ### Response #### Success Response (200) - **value** (null) - Indicates success. #### Response Example { "value": null } ``` -------------------------------- ### Get WebElement CSS Property in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/web_element.rs Retrieves the computed value of a specified CSS property for a web element. It returns a String within a WebDriverResult. If an invalid CSS property is requested, an empty string is returned. The example shows fetching the 'color' CSS property. ```rust pub async fn css_value(&self, name: impl IntoArcStr) -> WebDriverResult { self.handle.cmd(Command::GetElementCssProperty(self.element_id.clone(), name.into())).await?.value() } ``` -------------------------------- ### Get Metadata with Error Handling using `metadata().and_then()` in Rust Source: https://docs.rs/thirtyfour/latest/thirtyfour/error/type.WebDriverResult_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates obtaining file metadata and handling potential errors using `metadata().and_then()` in Rust. This example shows how to safely access file information, specifically the modification time, and checks for expected success and failure cases. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### POST /session/{session_id}/window/maximize Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=std%3A%3Avec Maximizes the browser window. ```APIDOC ## POST /session/{session_id}/window/maximize ### Description Maximizes the browser window. ### Method POST ### Endpoint /session/{session_id}/window/maximize ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the browser session. #### Request Body - **(empty)** - Required - An empty JSON object. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the operation. - **value** (object) - An empty object indicating success. #### Response Example ```json { "status": 0, "value": {} } ``` ``` -------------------------------- ### Get Named Cookie in Rust Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search= Fetches a specific cookie by its name. The function takes the cookie name as input and returns a `WebDriverResult` containing the `Cookie` object if found. The example shows how to retrieve a cookie named 'key' and print its value. This operation requires an active WebDriver session. ```rust /// Get the specified cookie. /// /// # Example: /// ```no_run /// # use thirtyfour::prelude::*; /// # use thirtyfour::support::block_on; /// # /// # fn main() -> WebDriverResult<()> { /// # block_on(async { /// # let caps = DesiredCapabilities::chrome(); /// # let driver = WebDriver::new("http://localhost:4444", caps).await?; /// let cookie = driver.get_named_cookie("key").await?; /// println!("Got cookie: {}", cookie.value); /// # driver.quit().await?; /// # Ok(()) /// # }) /// # } /// ``` pub async fn get_named_cookie(&self, name: impl IntoArcStr) -> WebDriverResult { self.cmd(Command::GetNamedCookie(name.into())).await?.value() } ``` -------------------------------- ### Conversion and Policy Operations (Rust) Source: https://docs.rs/thirtyfour/latest/thirtyfour/components/struct.ElementResolver_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates type conversions using `From`, `TryFrom`, `Into`, and `TryInto`. It also shows how to combine policies using `and` and `or` methods, creating more complex decision-making logic. ```rust fn from(t: T) -> T try_from(value: U) -> Result>::Error> into(self) -> U try_into(self) -> Result>::Error> and(self, other: P) -> And or(self, other: P) -> Or ``` -------------------------------- ### Get All Window Handles (Rust) Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/session/handle.rs_search=u32+-%3E+bool Retrieves a list of all unique identifiers for the currently open browser windows or tabs within the WebDriver session. This method is essential for managing multiple browser contexts. The example shows how to obtain these handles after potentially opening new tabs. It requires the 'thirtyfour' crate and its 'prelude' and 'support' modules. ```rust # use thirtyfour::prelude::* # use thirtyfour::support::block_on; # # fn main() -> WebDriverResult<()> { # block_on(async { # let caps = DesiredCapabilities::chrome(); # let driver = WebDriver::new("http://localhost:4444", caps).await?; // Get all window handles for the current session. let handles = driver.windows().await?; // Example usage: switch to the second window if it exists if handles.len() > 1 { driver.switch_to_window(handles[1].clone()).await?; } # driver.quit().await?; # Ok(()) # }) # } ``` -------------------------------- ### New Session API Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=u32+-%3E+bool Creates a new browser session with the specified capabilities. ```APIDOC ## POST /session ### Description Creates a new browser session. ### Method POST ### Endpoint /session ### Parameters #### Request Body - **capabilities** (Value) - Required - The desired capabilities for the new session. - **desiredCapabilities** (Value) - Required - The desired capabilities for the new session (legacy). ### Request Example ```json { "capabilities": {}, "desiredCapabilities": {} } ``` ### Response #### Success Response (200) - **sessionId** (string) - The ID of the newly created session. - **capabilities** (object) - The capabilities of the created session. #### Response Example ```json { "sessionId": "some-session-id", "capabilities": {} } ``` ``` -------------------------------- ### Rust: Implement CapabilitiesHelper Methods Source: https://docs.rs/thirtyfour/latest/thirtyfour/common/capabilities/desiredcapabilities/trait.CapabilitiesHelper This Rust code demonstrates the implementation of provided methods within the CapabilitiesHelper trait. These methods facilitate setting various browser and session configurations, such as enabling JavaScript, setting the browser version, and managing SSL certificates. ```rust fn set_base_capability( &mut self, key: &str, value: T, ) -> WebDriverResult<()> where T: Serialize { ... } fn set_version(&mut self, version: &str) -> WebDriverResult<()> { ... } fn set_platform(&mut self, platform: &str) -> WebDriverResult<()> { ... } fn set_javascript_enabled(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn set_database_enabled(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn set_location_context_enabled( &mut self, enabled: bool, ) -> WebDriverResult<()> { ... } fn set_application_cache_enabled( &mut self, enabled: bool, ) -> WebDriverResult<()> { ... } fn set_browser_connection_enabled( &mut self, enabled: bool, ) -> WebDriverResult<()> { ... } fn set_web_storage_enabled(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn accept_ssl_certs(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn accept_insecure_certs(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn set_rotatable(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn set_native_events(&mut self, enabled: bool) -> WebDriverResult<()> { ... } fn set_proxy(&mut self, proxy: Proxy) -> WebDriverResult<()> { ... } fn set_unexpected_alert_behaviour( &mut self, behaviour: AlertBehaviour, ) -> WebDriverResult<()> { ... } fn set_element_scroll_behaviour( &mut self, behaviour: ScrollBehaviour, ) -> WebDriverResult<()> { ... } fn handles_alerts(&self) -> Option { ... } fn css_selectors_enabled(&self) -> Option { ... } fn page_load_strategy(&self) -> WebDriverResult { ... } fn set_page_load_strategy( &mut self, strategy: PageLoadStrategy, ) -> WebDriverResult<()> { ... } ``` -------------------------------- ### Window Management API Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=u32+-%3E+bool Manages browser windows, including getting handles, switching, closing, and resizing. ```APIDOC ## GET /session/{sessionId}/title ### Description Retrieves the title of the current browser window. ### Method GET ### Endpoint /session/{sessionId}/title ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **value** (string) - The title of the current window. #### Response Example ```json { "value": "Example Domain" } ``` ## GET /session/{sessionId}/window ### Description Retrieves the current window handle. ### Method GET ### Endpoint /session/{sessionId}/window ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **value** (string) - The current window handle. #### Response Example ```json { "value": "window-handle-123" } ``` ## DELETE /session/{sessionId}/window ### Description Closes the current browser window. ### Method DELETE ### Endpoint /session/{sessionId}/window ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "status": "success" } ``` ## POST /session/{sessionId}/window ### Description Switches to a different browser window using its handle. ### Method POST ### Endpoint /session/{sessionId}/window ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. #### Request Body - **handle** (string) - Required - The handle of the window to switch to. ### Request Example ```json { "handle": "window-handle-456" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "status": "success" } ``` ## GET /session/{sessionId}/window/handles ### Description Retrieves the handles of all open browser windows. ### Method GET ### Endpoint /session/{sessionId}/window/handles ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **value** (array) - An array of window handles. #### Response Example ```json { "value": ["window-handle-123", "window-handle-456"] } ``` ## POST /session/{sessionId}/window/new ### Description Opens a new browser window (tab or window based on type). ### Method POST ### Endpoint /session/{sessionId}/window/new ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. #### Request Body - **type** (string) - Optional - The type of window to open ('window' or 'tab'). Defaults to 'tab'. ### Request Example ```json { "type": "window" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **value** (string) - The handle of the newly opened window. #### Response Example ```json { "status": "success", "value": "new-window-handle" } ``` ## GET /session/{sessionId}/rect ### Description Retrieves the dimensions and position of the current browser window. ### Method GET ### Endpoint /session/{sessionId}/rect ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **value** (object) - An object containing the window's rect properties. - **x** (number) - The x-coordinate of the window's top-left corner. - **y** (number) - The y-coordinate of the window's top-left corner. - **width** (number) - The width of the window. - **height** (number) - The height of the window. #### Response Example ```json { "value": { "x": 0, "y": 0, "width": 1024, "height": 768 } } ``` ## POST /session/{sessionId}/rect ### Description Sets the dimensions and position of the current browser window. ### Method POST ### Endpoint /session/{sessionId}/rect ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. #### Request Body - **x** (number) - Optional - The x-coordinate to set. - **y** (number) - Optional - The y-coordinate to set. - **width** (number) - Optional - The width to set. - **height** (number) - Optional - The height to set. ### Request Example ```json { "width": 800, "height": 600 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. - **value** (object) - An object containing the updated window's rect properties. #### Response Example ```json { "status": "success", "value": { "x": 0, "y": 0, "width": 800, "height": 600 } } ``` ## POST /session/{sessionId}/window/maximize ### Description Maximizes the current browser window. ### Method POST ### Endpoint /session/{sessionId}/window/maximize ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "status": "success" } ``` ## POST /session/{sessionId}/window/minimize ### Description Minimizes the current browser window. ### Method POST ### Endpoint /session/{sessionId}/window/minimize ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "status": "success" } ``` ## POST /session/{sessionId}/window/fullscreen ### Description Makes the current browser window fullscreen. ### Method POST ### Endpoint /session/{sessionId}/window/fullscreen ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### POST /session/{session_id}/window/minimize Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=std%3A%3Avec Minimizes the browser window. ```APIDOC ## POST /session/{session_id}/window/minimize ### Description Minimizes the browser window. ### Method POST ### Endpoint /session/{session_id}/window/minimize ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the browser session. #### Request Body - **(empty)** - Required - An empty JSON object. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the operation. - **value** (object) - An empty object indicating success. #### Response Example ```json { "status": 0, "value": {} } ``` ``` -------------------------------- ### Firefox Add-on Installation Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/extensions/addons/firefox/firefoxcommand.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs an add-on to the Firefox browser. The add-on can be temporary or permanent. ```APIDOC ## POST /session/{session_id}/moz/addon/install ### Description Installs the specified add-on to the Firefox browser. ### Method POST ### Endpoint /session/{session_id}/moz/addon/install ### Parameters #### Path Parameters - **session_id** (string) - Required - The ID of the WebDriver session. #### Request Body - **path** (string) - Required - The file path to the add-on. - **temporary** (boolean) - Optional - True if the add-on should be temporary. ### Request Example ```json { "path": "/path/to/your/addon.xpi", "temporary": true } ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the command. - **value** (object) - An empty object upon successful installation. #### Response Example ```json { "status": 0, "value": {} } ``` ``` -------------------------------- ### POST /session/{session_id}/window/fullscreen Source: https://docs.rs/thirtyfour/latest/src/thirtyfour/common/command.rs_search=std%3A%3Avec Puts the browser window into fullscreen mode. ```APIDOC ## POST /session/{session_id}/window/fullscreen ### Description Puts the browser window into fullscreen mode. ### Method POST ### Endpoint /session/{session_id}/window/fullscreen ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the browser session. #### Request Body - **(empty)** - Required - An empty JSON object. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the operation. - **value** (object) - An empty object indicating success. #### Response Example ```json { "status": 0, "value": {} } ``` ```