[][src]Struct thirtyfour::action_chain::ActionChain

pub struct ActionChain { /* fields omitted */ }

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:

This example is not tested
driver.action_chain().drag_and_drop_element(elem_src, elem_target).perform().await?;

Methods

impl ActionChain[src]

pub fn new(conn: Arc<RemoteConnectionAsync>, session_id: SessionId) -> Self[src]

Create a new ActionChain struct.

See WebDriver::action_chain() for more details.

pub async fn reset_actions<'_>(&'_ self) -> WebDriverResult<()>[src]

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

Example:

// Hold mouse button down on element.
let elem = driver.find_element(By::Id("button1")).await?;
driver.action_chain().click_and_hold_element(&elem).perform().await?;
let elem_result = driver.find_element(By::Id("button-result")).await?;
assert_eq!(elem_result.text().await?, "Button 1 down");
// Now reset all actions.
driver.action_chain().reset_actions().await?;
// Mouse button is now released.
assert_eq!(elem_result.text().await?, "Button 1 clicked");

pub async fn perform<'_>(&'_ self) -> WebDriverResult<()>[src]

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

pub fn click(self) -> Self[src]

Click and release the left mouse button.

Example:

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

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

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

Example:

let elem = driver.find_element(By::Id("button1")).await?;
driver.action_chain().click_element(&elem).perform().await?;

pub fn click_and_hold(self) -> Self[src]

Click the left mouse button and hold it down.

Example:

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

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

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

Example:

let elem = driver.find_element(By::Id("button1")).await?;
driver.action_chain().click_and_hold_element(&elem).perform().await?;

pub fn context_click(self) -> Self[src]

Click and release the right mouse button.

Example:

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

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

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

Example:

let elem = driver.find_element(By::Id("button1")).await?;
driver.action_chain().context_click_element(&elem).perform().await?;

pub fn double_click(self) -> Self[src]

Double-click the left mouse button.

Example:

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

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

Double-click on the specified element.

Example:

let elem = driver.find_element(By::Id("button1")).await?;
driver.action_chain().double_click_element(&elem).perform().await?;

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

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/7744

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

pub fn drag_and_drop_by_offset(self, x_offset: i32, y_offset: i32) -> Self[src]

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/7744

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

pub fn drag_and_drop_element_by_offset(
    self,
    element: &WebElement,
    x_offset: i32,
    y_offset: i32
) -> Self
[src]

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/7744

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

pub fn key_down<T>(self, value: T) -> Self where
    T: Into<char>, 
[src]

Press the specified key down.

Example:

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

pub fn key_down_on_element<T>(self, element: &WebElement, value: T) -> Self where
    T: Into<char>, 
[src]

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

Example:

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

pub fn key_up<T>(self, value: T) -> Self where
    T: Into<char>, 
[src]

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

Example:

use thirtyfour::Keys;
let elem = driver.find_element(By::Name("input1")).await?;
elem.send_keys("selenium").await?;
assert_eq!(elem.text().await?, "selenium");
driver.action_chain()
    .key_down_on_element(&elem, Keys::Control).key_down('a')
    .key_up(Keys::Control).key_up('a')
    .key_down('b')
    .perform().await?;
assert_eq!(elem.text().await?, "b");

pub fn key_up_on_element<T>(self, element: &WebElement, value: T) -> Self where
    T: Into<char>, 
[src]

Click the specified element and release the specified key.

Example:

use thirtyfour::Keys;
let elem = driver.find_element(By::Name("input1")).await?;
elem.send_keys("selenium").await?;
assert_eq!(elem.text().await?, "selenium");
driver.action_chain()
    .key_down_on_element(&elem, Keys::Control).key_down('a')
    .key_up_on_element(&elem, 'a').key_up_on_element(&elem, Keys::Control)
    .key_down('b')
    .perform().await?;
assert_eq!(elem.text().await?, "b");

pub fn move_to(self, x: i32, y: i32) -> Self[src]

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

Example:

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

pub fn move_by_offset(self, x_offset: i32, y_offset: i32) -> Self[src]

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

Example:

let elem1 = driver.find_element(By::Id("button1")).await?;
let elem2 = driver.find_element(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 i32 - elem1.rect().await?.center().0 as i32;
driver.action_chain()
    .move_to_element_center(&elem1)
    .move_by_offset(offset, 0)
    .click()
    .perform().await?;

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

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

Example:

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

pub fn move_to_element_with_offset(
    self,
    element: &WebElement,
    x_offset: i32,
    y_offset: i32
) -> Self
[src]

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_element(By::Id("button-result")).await?;
let width = elem.rect().await?.width;
driver.action_chain()
    .move_to_element_with_offset(&elem, (-width / 2.0) as i32, 0)
    .drag_and_drop_by_offset(width as i32, 0)
    .key_down(Keys::Control)
    .key_down('c').key_up('c')
    .key_up(Keys::Control)
    .perform().await?;

// Now paste the text into the input field.
let elem_tgt = driver.find_element(By::Name("input1")).await?;
elem_tgt.send_keys(Keys::Control + "v").await?;

pub fn release(self) -> Self[src]

Release the left mouse button.

Example:

driver.action_chain().release().perform().await?;

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

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

Example:

driver.action_chain().release_on_element(&elem).perform().await?;

pub fn send_keys<S>(self, text: S) -> Self where
    S: Into<TypingData>, 
[src]

Send the specified keystrokes to the active element.

Example:

use thirtyfour::Keys;
let elem = driver.find_element(By::Name("input1")).await?;
let button = driver.find_element(By::Id("button-set")).await?;
driver.action_chain()
    .click_element(&elem)
    .send_keys("selenium")
    .click_element(&button)
    .perform().await?;

pub fn send_keys_to_element<S>(self, element: &WebElement, text: S) -> Self where
    S: Into<TypingData>, 
[src]

Click on the specified element and send the specified keystrokes.

Example:

use thirtyfour::Keys;
let elem = driver.find_element(By::Name("input1")).await?;
let button = driver.find_element(By::Id("button-set")).await?;
driver.action_chain()
    .send_keys_to_element(&elem, "selenium")
    .click_element(&button)
    .perform().await?;

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,