BrowserSession

Struct BrowserSession 

Source
pub struct BrowserSession { /* private fields */ }
Expand description

A browser session that wraps thirtyfour’s WebDriver.

This is the core abstraction for browser automation in ADK. It can be shared across multiple tools via Arc<BrowserSession>.

Implementations§

Source§

impl BrowserSession

Source

pub fn new(config: BrowserConfig) -> Self

Create a new browser session with the given configuration.

Note: This does not start the browser immediately. Call start() to initialize the WebDriver connection.

Source

pub fn with_defaults() -> Self

Create a browser session with default configuration.

Source

pub async fn start(&self) -> Result<()>

Start the browser session by connecting to WebDriver.

Source

pub async fn stop(&self) -> Result<()>

Stop the browser session.

Source

pub async fn is_active(&self) -> bool

Check if the session is active.

Source

pub fn config(&self) -> &BrowserConfig

Get the configuration.

Source

pub async fn navigate(&self, url: &str) -> Result<()>

Navigate to a URL.

Source

pub async fn current_url(&self) -> Result<String>

Get the current URL.

Source

pub async fn title(&self) -> Result<String>

Get the page title.

Source

pub async fn find_element(&self, selector: &str) -> Result<WebElement>

Find an element by CSS selector.

Source

pub async fn find_elements(&self, selector: &str) -> Result<Vec<WebElement>>

Find multiple elements by CSS selector.

Source

pub async fn find_by_xpath(&self, xpath: &str) -> Result<WebElement>

Find element by XPath.

Source

pub async fn click(&self, selector: &str) -> Result<()>

Click an element by selector.

Source

pub async fn type_text(&self, selector: &str, text: &str) -> Result<()>

Type text into an element.

Source

pub async fn clear(&self, selector: &str) -> Result<()>

Clear an input field.

Source

pub async fn get_text(&self, selector: &str) -> Result<String>

Get text content of an element.

Source

pub async fn get_attribute( &self, selector: &str, attribute: &str, ) -> Result<Option<String>>

Get an attribute value.

Source

pub async fn screenshot(&self) -> Result<String>

Take a screenshot (returns base64-encoded PNG).

Source

pub async fn screenshot_element(&self, selector: &str) -> Result<String>

Take a screenshot of a specific element.

Source

pub async fn execute_script(&self, script: &str) -> Result<Value>

Execute JavaScript and return result.

Source

pub async fn execute_async_script(&self, script: &str) -> Result<Value>

Execute async JavaScript and return result.

Source

pub async fn wait_for_element( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement>

Wait for an element to be present.

Source

pub async fn wait_for_clickable( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement>

Wait for an element to be clickable.

Source

pub async fn page_source(&self) -> Result<String>

Get page source HTML.

Source

pub async fn back(&self) -> Result<()>

Go back in history.

Source

pub async fn forward(&self) -> Result<()>

Go forward in history.

Source

pub async fn refresh(&self) -> Result<()>

Refresh the current page.

Source

pub async fn get_all_cookies(&self) -> Result<Vec<Value>>

Get all cookies.

Get a cookie by name.

Add a cookie.

Delete a cookie.

Source

pub async fn delete_all_cookies(&self) -> Result<()>

Delete all cookies.

Source

pub async fn list_windows(&self) -> Result<(Vec<String>, String)>

List all windows/tabs.

Source

pub async fn new_tab(&self) -> Result<String>

Open a new tab.

Source

pub async fn new_window(&self) -> Result<String>

Open a new window.

Source

pub async fn switch_to_window(&self, handle: &str) -> Result<()>

Switch to a window by handle.

Source

pub async fn close_window(&self) -> Result<()>

Close the current window.

Source

pub async fn maximize_window(&self) -> Result<()>

Maximize window.

Source

pub async fn minimize_window(&self) -> Result<()>

Minimize window.

Source

pub async fn set_window_rect( &self, x: i32, y: i32, width: u32, height: u32, ) -> Result<()>

Set window size and position.

Source

pub async fn switch_to_frame_by_index(&self, index: u16) -> Result<()>

Switch to frame by index.

Source

pub async fn switch_to_frame_by_selector(&self, selector: &str) -> Result<()>

Switch to frame by selector.

Source

pub async fn switch_to_parent_frame(&self) -> Result<()>

Switch to parent frame.

Source

pub async fn switch_to_default_content(&self) -> Result<()>

Switch to default content.

Source

pub async fn drag_and_drop( &self, source_selector: &str, target_selector: &str, ) -> Result<()>

Drag and drop.

Source

pub async fn right_click(&self, selector: &str) -> Result<()>

Right-click (context click).

Source

pub async fn focus_element(&self, selector: &str) -> Result<()>

Focus an element.

Source

pub async fn get_element_state(&self, selector: &str) -> Result<ElementState>

Get element state.

Source

pub async fn press_key( &self, key: &str, selector: Option<&str>, _modifiers: &[&str], ) -> Result<()>

Press a key.

Source

pub async fn upload_file(&self, selector: &str, file_path: &str) -> Result<()>

Upload a file.

Source

pub async fn print_to_pdf(&self, landscape: bool, scale: f64) -> Result<String>

Print page to PDF.

Trait Implementations§

Source§

impl Drop for BrowserSession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more