thirtyfour::action_chain

Struct ActionChain

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

The ActionChain struct allows you to perform multiple input actions in a sequence, including drag-and-drop, send keystrokes to an element, and hover the mouse over an element.

The easiest way to construct an ActionChain struct is via the WebDriver struct.

§Example:

driver
    .action_chain()
    .drag_and_drop_element(elem_src, elem_target)
    .perform()
    .await?;

Implementations§

Source§

impl ActionChain

Source

pub fn new(handle: SessionHandle) -> Self

Create a new ActionChain struct.

See WebDriver::action_chain() for more details.

Source

pub async fn reset_actions(&self) -> WebDriverResult<()>

Reset all actions, reverting all input devices back to default states.

§Example:
// Hold mouse button down on element.
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .click_and_hold_element(&elem)
    .perform()
    .await?;

// Now reset all actions.
driver.action_chain().reset_actions().await?;

// Mouse button is now released.
Source

pub async fn perform(self) -> WebDriverResult<()>

Perform the action sequence. No actions are actually performed until this method is called.

Source

pub fn click(self) -> Self

Click and release the left mouse button.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .move_to_element_center(&elem)
    .click()
    .perform()
    .await?;
Source

pub fn click_element(self, element: &WebElement) -> Self

Click on the specified element using the left mouse button and release.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .click_element(&elem)
    .perform()
    .await?;
Source

pub fn click_and_hold(self) -> Self

Click the left mouse button and hold it down.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .move_to_element_center(&elem)
    .click_and_hold()
    .perform()
    .await?;
Source

pub fn click_and_hold_element(self, element: &WebElement) -> Self

Click on the specified element using the left mouse button and hold the button down.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .click_and_hold_element(&elem)
    .perform()
    .await?;
Source

pub fn context_click(self) -> Self

Click and release the right mouse button.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .move_to_element_center(&elem)
    .context_click()
    .perform()
    .await?;
Source

pub fn context_click_element(self, element: &WebElement) -> Self

Click on the specified element using the right mouse button and release.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .context_click_element(&elem)
    .perform()
    .await?;
Source

pub fn double_click(self) -> Self

Double-click the left mouse button.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .move_to_element_center(&elem)
    .double_click()
    .perform()
    .await?;
Source

pub fn double_click_element(self, element: &WebElement) -> Self

Double-click on the specified element.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .double_click_element(&elem)
    .perform()
    .await?;
Source

pub fn drag_and_drop_element( self, source: &WebElement, target: &WebElement, ) -> Self

Drag the mouse cursor from the center of the source element to the center of the target element.

This method is not working correctly due to a selenium bug

It appears selenium has a bug in the drag and drop feature causing it to start the drag but not perform the drop. See https://github.com/SeleniumHQ/selenium/issues/8003

This method has been confirmed to produce identical JSON output compared to the python selenium library (which also fails due to the same bug).

Source

pub fn drag_and_drop_by_offset(self, x_offset: i64, y_offset: i64) -> Self

Drag the mouse cursor by the specified X and Y offsets.

This method is not working correctly due to a selenium bug

It appears selenium has a bug in the drag and drop feature causing it to start the drag but not perform the drop. See https://github.com/SeleniumHQ/selenium/issues/8003

This method has been confirmed to produce identical JSON output compared to the python selenium library (which also fails due to the same bug).

Source

pub fn drag_and_drop_element_by_offset( self, element: &WebElement, x_offset: i64, y_offset: i64, ) -> Self

Drag the mouse cursor by the specified X and Y offsets, starting from the center of the specified element.

This method is not working correctly due to a selenium bug

It appears selenium has a bug in the drag and drop feature causing it to start the drag but not perform the drop. See https://github.com/SeleniumHQ/selenium/issues/8003

This method has been confirmed to produce identical JSON output compared to the python selenium library (which also fails due to the same bug).

Source

pub fn key_down(self, value: impl Into<char>) -> Self

Press the specified key down.

§Example:
let elem = driver.find(By::Name("input1")).await?;
driver
    .action_chain()
    .click_element(&elem)
    .key_down('a')
    .perform().await?;
Source

pub fn key_down_on_element( self, element: &WebElement, value: impl Into<char>, ) -> Self

Click the specified element and then press the specified key down.

§Example:
let elem = driver.find(By::Name("input1")).await?;
driver
    .action_chain()
    .key_down_on_element(&elem, 'a')
    .perform()
    .await?;
Source

pub fn key_up(self, value: impl Into<char>) -> Self

Release the specified key. This usually follows a key_down() action.

§Example:
let elem = driver.find(By::Name("input1")).await?;
elem.send_keys("selenium").await?;
driver
    .action_chain()
    .key_down_on_element(&elem, Key::Control)
    .key_down('a')
    .key_up(Key::Control)
    .key_up('a')
    .key_down('b')
    .perform()
    .await?;
Source

pub fn key_up_on_element( self, element: &WebElement, value: impl Into<char>, ) -> Self

Click the specified element and release the specified key.

§Example:
let elem = driver.find(By::Name("input1")).await?;
elem.send_keys("selenium").await?;
assert_eq!(elem.value().await?.unwrap(), "selenium");
driver
    .action_chain()
    .key_down_on_element(&elem, Key::Control)
    .key_down('a')
    .key_up_on_element(&elem, 'a')
    .key_up_on_element(&elem, Key::Control)
    .key_down('b')
    .perform()
    .await?;
assert_eq!(elem.value().await?.unwrap(), "b");
Source

pub fn move_to(self, x: i64, y: i64) -> Self

Move the mouse cursor to the specified X and Y coordinates.

§Example:
let elem = driver.find(By::Id("button1")).await?;
let center = elem.rect().await?.icenter();
driver
    .action_chain()
    .move_to(center.0, center.1)
    .click()
    .perform()
    .await?;
Source

pub fn move_by_offset(self, x_offset: i64, y_offset: i64) -> Self

Move the mouse cursor by the specified X and Y offsets.

§Example:
let elem1 = driver.find(By::Id("button1")).await?;
let elem2 = driver.find(By::Id("button2")).await?;

// We will calculate the distance between the two center points and then
// use action_chain() to move to the second button before clicking.
let offset = elem2.rect().await?.center().0 as i64 - elem1.rect().await?.center().0 as i64;
driver
    .action_chain()
    .move_to_element_center(&elem1)
    .move_by_offset(offset, 0)
    .click()
    .perform()
    .await?;
Source

pub fn move_to_element_center(self, element: &WebElement) -> Self

Move the mouse cursor to the center of the specified element.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .move_to_element_center(&elem)
    .click()
    .perform()
    .await?;
Source

pub fn move_to_element_with_offset( self, element: &WebElement, x_offset: i64, y_offset: i64, ) -> Self

Move the mouse cursor to the specified offsets relative to the specified element’s center position.

§Example:
// Select the text in the source element and copy it to the clipboard.
let elem = driver.find(By::Id("button-result")).await?;
let width = elem.rect().await?.width;
driver
    .action_chain()
    .move_to_element_with_offset(&elem, (-(width as f64) / 2.0) as i64, 0)
    .drag_and_drop_by_offset(width as i64, 0)
    .key_down(Key::Control)
    .key_down('c')
    .key_up('c')
    .key_up(Key::Control)
    .perform()
    .await?;
Source

pub fn release(self) -> Self

Release the left mouse button.

§Example:
let elem = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .click_and_hold_element(&elem)
    .release()
    .perform()
    .await?;
Source

pub fn release_on_element(self, element: &WebElement) -> Self

Move the mouse to the specified element and release the mouse button.

§Example:
let elem1 = driver.find(By::Id("source-element-id")).await?;
let elem2 = driver.find(By::Id("target-element-id")).await?;
driver
    .action_chain()
    .click_and_hold_element(&elem1)
    .release_on_element(&elem2)
    .perform()
    .await?;
Source

pub fn send_keys(self, text: impl AsRef<str>) -> Self

Send the specified keystrokes to the active element.

§Example:
use thirtyfour::Key;
let elem = driver.find(By::Name("input1")).await?;
let button = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .click_element(&elem)
    .send_keys("selenium")
    .click_element(&button)
    .perform()
    .await?;
Source

pub fn send_keys_to_element( self, element: &WebElement, text: impl AsRef<str>, ) -> Self

Click on the specified element and send the specified keystrokes.

§Example:
let elem = driver.find(By::Name("input1")).await?;
let button = driver.find(By::Id("button1")).await?;
driver
    .action_chain()
    .send_keys_to_element(&elem, "selenium")
    .click_element(&button)
    .perform()
    .await?;

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, 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