thirtyfour/action_chain.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
use crate::actions::{
ActionSequence, InputSource, KeyAction, KeyActions, MouseActions, PointerAction,
MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT,
};
use crate::session::handle::SessionHandle;
use crate::{error::WebDriverResult, WebElement};
use std::time::Duration;
/// 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:
/// ```ignore
/// driver
/// .action_chain()
/// .drag_and_drop_element(elem_src, elem_target)
/// .perform()
/// .await?;
/// ```
pub struct ActionChain {
handle: SessionHandle,
key_actions: Option<KeyActions>,
mouse_actions: Option<MouseActions>,
}
impl ActionChain {
/// Create a new ActionChain struct.
///
/// See [WebDriver::action_chain()](../struct.WebDriver.html#method.action_chain)
/// for more details.
pub fn new(handle: SessionHandle) -> Self {
ActionChain {
handle,
key_actions: Some(KeyActions::new("key".to_string())),
mouse_actions: Some(MouseActions::new("mouse".to_string())),
}
}
/// Add a pause for the key sequence. Usually required after adding a mouse event,
/// to keep the key sequence in sync with the mouse sequence.
fn add_key_pause(&mut self) {
self.key_actions = Some(self.key_actions.take().unwrap().pause(Duration::from_millis(0)));
}
fn add_key_down(&mut self, key: char) {
self.key_actions = Some(self.key_actions.take().unwrap().then(KeyAction::Down {
value: key,
}));
self.add_mouse_pause();
}
fn add_key_up(&mut self, key: char) {
self.key_actions = Some(self.key_actions.take().unwrap().then(KeyAction::Up {
value: key,
}));
self.add_mouse_pause();
}
/// Add a pause for the mouse sequence. Usually required after adding a key event,
/// to keep the mouse sequence in sync with the key sequence.
fn add_mouse_pause(&mut self) {
self.mouse_actions =
Some(self.mouse_actions.take().unwrap().pause(Duration::from_millis(0)));
}
fn add_mouse_down(&mut self, button: u64) {
self.mouse_actions = Some(self.mouse_actions.take().unwrap().then(PointerAction::Down {
button,
}));
self.add_key_pause();
}
fn add_mouse_up(&mut self, button: u64) {
self.mouse_actions = Some(self.mouse_actions.take().unwrap().then(PointerAction::Up {
button,
}));
self.add_key_pause();
}
fn add_move_to_element(&mut self, element: &WebElement, x_offset: i64, y_offset: i64) {
self.mouse_actions =
Some(self.mouse_actions.take().unwrap().then(PointerAction::MoveToElement {
element: element.element.clone(),
duration: None,
x: x_offset,
y: y_offset,
}));
self.add_key_pause();
}
fn add_move_to(&mut self, x: i64, y: i64) {
self.mouse_actions = Some(self.mouse_actions.take().unwrap().then(PointerAction::MoveTo {
duration: None,
x,
y,
}));
self.add_key_pause();
}
fn add_move_by(&mut self, x: i64, y: i64) {
self.mouse_actions = Some(self.mouse_actions.take().unwrap().then(PointerAction::MoveBy {
duration: None,
x,
y,
}));
self.add_key_pause();
}
/// Reset all actions, reverting all input devices back to default states.
///
/// # 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?;
/// // 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.
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub async fn reset_actions(&self) -> WebDriverResult<()> {
self.handle.client.release_actions().await?;
Ok(())
}
/// Perform the action sequence. No actions are actually performed until
/// this method is called.
pub async fn perform(self) -> WebDriverResult<()> {
self.handle
.client
.perform_actions(vec![
ActionSequence::from(self.key_actions.unwrap()),
ActionSequence::from(self.mouse_actions.unwrap()),
])
.await?;
Ok(())
}
/// Click and release the left mouse button.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .move_to_element_center(&elem)
/// .click()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn click(mut self) -> Self {
self.add_mouse_down(MOUSE_BUTTON_LEFT);
self.add_mouse_up(MOUSE_BUTTON_LEFT);
self
}
/// Click on the specified element using the left mouse button and release.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .click_element(&elem)
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn click_element(mut self, element: &WebElement) -> Self {
self.add_move_to_element(element, 0, 0);
self.click()
}
/// Click the left mouse button and hold it down.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .move_to_element_center(&elem)
/// .click_and_hold()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn click_and_hold(mut self) -> Self {
self.add_mouse_down(MOUSE_BUTTON_LEFT);
self
}
/// Click on the specified element using the left mouse button and
/// hold the button down.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .click_and_hold_element(&elem)
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn click_and_hold_element(mut self, element: &WebElement) -> Self {
self.add_move_to_element(element, 0, 0);
self.click_and_hold()
}
/// Click and release the right mouse button.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .move_to_element_center(&elem)
/// .context_click()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn context_click(mut self) -> Self {
self.add_mouse_down(MOUSE_BUTTON_RIGHT);
self.add_mouse_up(MOUSE_BUTTON_RIGHT);
self
}
/// Click on the specified element using the right mouse button and release.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .context_click_element(&elem)
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn context_click_element(mut self, element: &WebElement) -> Self {
self.add_move_to_element(element, 0, 0);
self.context_click()
}
/// Double-click the left mouse button.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .move_to_element_center(&elem)
/// .double_click()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn double_click(self) -> Self {
self.click().click()
}
/// Double-click on the specified element.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .double_click_element(&elem)
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn double_click_element(mut self, element: &WebElement) -> Self {
self.add_move_to_element(element, 0, 0);
self.double_click()
}
/// 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](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).
pub fn drag_and_drop_element(self, source: &WebElement, target: &WebElement) -> Self {
self.click_and_hold_element(source).release_on_element(target)
}
/// 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](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).
pub fn drag_and_drop_by_offset(self, x_offset: i64, y_offset: i64) -> Self {
self.click_and_hold().move_by_offset(x_offset, y_offset)
}
/// 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](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).
pub fn drag_and_drop_element_by_offset(
self,
element: &WebElement,
x_offset: i64,
y_offset: i64,
) -> Self {
self.click_and_hold_element(element).move_by_offset(x_offset, y_offset)
}
/// Press the specified key down.
///
/// # 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 elem = driver.find(By::Name("input1")).await?;
/// driver
/// .action_chain()
/// .click_element(&elem)
/// .key_down('a')
/// .perform().await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn key_down(mut self, value: impl Into<char>) -> Self {
self.add_key_down(value.into());
self
}
/// Click the specified element and then press the specified key down.
///
/// # 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 elem = driver.find(By::Name("input1")).await?;
/// driver
/// .action_chain()
/// .key_down_on_element(&elem, 'a')
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn key_down_on_element(self, element: &WebElement, value: impl Into<char>) -> Self {
self.click_element(element).key_down(value)
}
/// Release the specified key. This usually follows a `key_down()` action.
///
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn key_up(mut self, value: impl Into<char>) -> Self {
self.add_key_up(value.into());
self
}
/// Click the specified element and release the specified key.
///
/// # 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 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");
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn key_up_on_element(self, element: &WebElement, value: impl Into<char>) -> Self {
self.click_element(element).key_up(value)
}
/// Move the mouse cursor to the specified X and Y coordinates.
///
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn move_to(mut self, x: i64, y: i64) -> Self {
self.add_move_to(x, y);
self
}
/// Move the mouse cursor by the specified X and Y offsets.
///
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn move_by_offset(mut self, x_offset: i64, y_offset: i64) -> Self {
self.add_move_by(x_offset, y_offset);
self
}
/// Move the mouse cursor to the center of the specified element.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .move_to_element_center(&elem)
/// .click()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn move_to_element_center(mut self, element: &WebElement) -> Self {
self.add_move_to_element(element, 0, 0);
self
}
/// Move the mouse cursor to the specified offsets relative to the specified
/// element's center position.
///
/// # 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?;
/// // 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn move_to_element_with_offset(
mut self,
element: &WebElement,
x_offset: i64,
y_offset: i64,
) -> Self {
self.add_move_to_element(element, x_offset, y_offset);
self
}
/// Release the left mouse button.
///
/// # 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 elem = driver.find(By::Id("button1")).await?;
/// driver
/// .action_chain()
/// .click_and_hold_element(&elem)
/// .release()
/// .perform()
/// .await?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn release(mut self) -> Self {
self.add_mouse_up(MOUSE_BUTTON_LEFT);
self
}
/// Move the mouse to the specified element and release the mouse button.
///
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn release_on_element(self, element: &WebElement) -> Self {
self.move_to_element_center(element).release()
}
/// Send the specified keystrokes to the active element.
///
/// # Example:
/// ```no_run
/// use thirtyfour::Key;
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn send_keys(mut self, text: impl AsRef<str>) -> Self {
for c in text.as_ref().chars() {
self = self.key_down(c).key_up(c);
}
self
}
/// Click on the specified element and send the specified keystrokes.
///
/// # 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 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?;
/// # driver.quit().await?;
/// # Ok(())
/// # })
/// # }
/// ```
pub fn send_keys_to_element(self, element: &WebElement, text: impl AsRef<str>) -> Self {
self.click_element(element).send_keys(text)
}
}