pub struct Tab { /* private fields */ }Expand description
A handle to a browser tab.
Tabs provide methods for navigation, scripting, and element interaction.
Implementations§
Source§impl Tab
impl Tab
Sourcepub async fn find_element(&self, by: By) -> Result<Element>
pub async fn find_element(&self, by: By) -> Result<Element>
Finds a single element using a locator strategy.
§Example
use firefox_webdriver::By;
// CSS selector
let btn = tab.find_element(By::Css("#submit")).await?;
// By ID
let form = tab.find_element(By::Id("login-form")).await?;
// By text content
let link = tab.find_element(By::Text("Click here")).await?;
// By XPath
let btn = tab.find_element(By::XPath("//button[@type='submit']")).await?;Source§impl Tab
impl Tab
Sourcepub async fn wait_for_element(&self, by: By) -> Result<Element>
pub async fn wait_for_element(&self, by: By) -> Result<Element>
Waits for an element using a locator strategy.
Uses MutationObserver (no polling). Times out after 30 seconds.
§Example
use firefox_webdriver::By;
let btn = tab.wait_for_element(By::Id("submit")).await?;
let link = tab.wait_for_element(By::Css("a.login")).await?;
let el = tab.wait_for_element(By::XPath("//button")).await?;Sourcepub async fn wait_for_element_timeout(
&self,
by: By,
timeout_duration: Duration,
) -> Result<Element>
pub async fn wait_for_element_timeout( &self, by: By, timeout_duration: Duration, ) -> Result<Element>
Waits for an element using a locator strategy with custom timeout.
Sourcepub async fn on_element_added<F>(
&self,
by: By,
callback: F,
) -> Result<SubscriptionId>
pub async fn on_element_added<F>( &self, by: By, callback: F, ) -> Result<SubscriptionId>
Registers a callback for when elements matching the selector appear.
§Returns
Subscription ID for later unsubscription.
Sourcepub async fn on_element_removed<F>(
&self,
element_id: &ElementId,
callback: F,
) -> Result<()>
pub async fn on_element_removed<F>( &self, element_id: &ElementId, callback: F, ) -> Result<()>
Registers a callback for when a specific element is removed.
Sourcepub async fn unsubscribe(&self, subscription_id: &SubscriptionId) -> Result<()>
pub async fn unsubscribe(&self, subscription_id: &SubscriptionId) -> Result<()>
Unsubscribes from element observation.
Source§impl Tab
impl Tab
Sourcepub async fn switch_to_frame(&self, iframe: &Element) -> Result<Tab>
pub async fn switch_to_frame(&self, iframe: &Element) -> Result<Tab>
Sourcepub async fn switch_to_frame_by_index(&self, index: usize) -> Result<Tab>
pub async fn switch_to_frame_by_index(&self, index: usize) -> Result<Tab>
Sourcepub async fn switch_to_frame_by_url(&self, url_pattern: &str) -> Result<Tab>
pub async fn switch_to_frame_by_url(&self, url_pattern: &str) -> Result<Tab>
Switches to a frame by URL pattern.
Supports wildcards (* for any characters, ? for single character).
§Arguments
url_pattern- URL pattern with optional wildcards
Sourcepub async fn switch_to_parent_frame(&self) -> Result<Tab>
pub async fn switch_to_parent_frame(&self) -> Result<Tab>
Switches to the parent frame.
Sourcepub fn switch_to_main_frame(&self) -> Tab
pub fn switch_to_main_frame(&self) -> Tab
Switches to the main (top-level) frame.
Sourcepub async fn get_frame_count(&self) -> Result<usize>
pub async fn get_frame_count(&self) -> Result<usize>
Gets the count of direct child frames.
Sourcepub async fn get_all_frames(&self) -> Result<Vec<FrameInfo>>
pub async fn get_all_frames(&self) -> Result<Vec<FrameInfo>>
Gets information about all frames in the tab.
Source§impl Tab
impl Tab
Source§impl Tab
impl Tab
Sourcepub async fn set_block_rules(&self, patterns: &[&str]) -> Result<()>
pub async fn set_block_rules(&self, patterns: &[&str]) -> Result<()>
Sourcepub async fn clear_block_rules(&self) -> Result<()>
pub async fn clear_block_rules(&self) -> Result<()>
Clears all URL block rules.
Sourcepub async fn intercept_request<F>(&self, callback: F) -> Result<InterceptId>
pub async fn intercept_request<F>(&self, callback: F) -> Result<InterceptId>
Sourcepub async fn intercept_request_headers<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_request_headers<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts request headers with a callback.
Sourcepub async fn intercept_request_body<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_request_body<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts request body for logging (read-only).
Sourcepub async fn intercept_response<F>(&self, callback: F) -> Result<InterceptId>
pub async fn intercept_response<F>(&self, callback: F) -> Result<InterceptId>
Intercepts response headers with a callback.
Sourcepub async fn intercept_response_body<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_response_body<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts response body with a callback.
Sourcepub async fn stop_intercept(&self, intercept_id: &InterceptId) -> Result<()>
pub async fn stop_intercept(&self, intercept_id: &InterceptId) -> Result<()>
Stops network interception.
§Arguments
intercept_id- The intercept ID returned from intercept methods
Source§impl Tab
impl Tab
Sourcepub async fn set_proxy(&self, config: ProxyConfig) -> Result<()>
pub async fn set_proxy(&self, config: ProxyConfig) -> Result<()>
Sourcepub async fn clear_proxy(&self) -> Result<()>
pub async fn clear_proxy(&self) -> Result<()>
Clears the proxy for this tab.
Source§impl Tab
impl Tab
Sourcepub fn screenshot(&self) -> ScreenshotBuilder<'_>
pub fn screenshot(&self) -> ScreenshotBuilder<'_>
Creates a screenshot builder for capturing page screenshots.
Uses the browser’s native screenshot API for accurate pixel capture.
§Example
// PNG screenshot as base64
let data = tab.screenshot().png().capture().await?;
// JPEG screenshot saved to file
tab.screenshot().jpeg(85).save("page.jpg").await?;Sourcepub async fn capture_screenshot(&self) -> Result<String>
pub async fn capture_screenshot(&self) -> Result<String>
Captures a PNG screenshot and returns base64-encoded data.
Shorthand for tab.screenshot().png().capture().await.
Source§impl Tab
impl Tab
Sourcepub async fn execute_script(&self, script: &str) -> Result<Value>
pub async fn execute_script(&self, script: &str) -> Result<Value>
Sourcepub async fn execute_async_script(&self, script: &str) -> Result<Value>
pub async fn execute_async_script(&self, script: &str) -> Result<Value>
Executes asynchronous JavaScript in the page context.
The script should return a Promise or use async/await.
Source§impl Tab
impl Tab
Sourcepub async fn scroll_to_top(&self) -> Result<()>
pub async fn scroll_to_top(&self) -> Result<()>
Scrolls to the top of the page.
Sourcepub async fn scroll_to_bottom(&self) -> Result<()>
pub async fn scroll_to_bottom(&self) -> Result<()>
Scrolls to the bottom of the page.
Sourcepub async fn get_scroll_position(&self) -> Result<(i32, i32)>
pub async fn get_scroll_position(&self) -> Result<(i32, i32)>
Sourcepub async fn get_page_size(&self) -> Result<(i32, i32)>
pub async fn get_page_size(&self) -> Result<(i32, i32)>
Source§impl Tab
impl Tab
Sourcepub async fn local_storage_get(&self, key: &str) -> Result<Option<String>>
pub async fn local_storage_get(&self, key: &str) -> Result<Option<String>>
Gets a value from localStorage.
Sourcepub async fn local_storage_set(&self, key: &str, value: &str) -> Result<()>
pub async fn local_storage_set(&self, key: &str, value: &str) -> Result<()>
Sets a value in localStorage.
Sourcepub async fn local_storage_delete(&self, key: &str) -> Result<()>
pub async fn local_storage_delete(&self, key: &str) -> Result<()>
Deletes a key from localStorage.
Sourcepub async fn local_storage_clear(&self) -> Result<()>
pub async fn local_storage_clear(&self) -> Result<()>
Clears all localStorage.
Source§impl Tab
impl Tab
Sourcepub async fn session_storage_get(&self, key: &str) -> Result<Option<String>>
pub async fn session_storage_get(&self, key: &str) -> Result<Option<String>>
Gets a value from sessionStorage.
Sourcepub async fn session_storage_set(&self, key: &str, value: &str) -> Result<()>
pub async fn session_storage_set(&self, key: &str, value: &str) -> Result<()>
Sets a value in sessionStorage.
Sourcepub async fn session_storage_delete(&self, key: &str) -> Result<()>
pub async fn session_storage_delete(&self, key: &str) -> Result<()>
Deletes a key from sessionStorage.
Sourcepub async fn session_storage_clear(&self) -> Result<()>
pub async fn session_storage_clear(&self) -> Result<()>
Clears all sessionStorage.