"Reprint" Webdriver commonly used mouse/keyboard operation

Source: Internet
Author: User
Tags xpath

Note: Driver is an instance of Webdriver, XPath is an XPath string for an element, and is used in this article to position the element in an XPath manner.

1, the right mouse button click operation:
Actions action = new actions (driver);
Action.contextclick (Driver.findelement (By.xpath (XPath)));


2, the left mouse button double-click Operation:
Actions action = new actions (driver);
Action.doubleclick (Driver.findelement (By.xpath (XPath)));


3, the left mouse button to press the operation:
Actions action = new actions (driver);
Action.clickandhold (Driver.findelement (By.xpath (XPath)));


4, the left mouse button lifting operation:
Actions action = new actions (driver);
Action.release (Driver.findelement (By.xpath (XPath)));


5, move the mouse to the element operation:
Actions action = new actions (driver);
Action.movetoelement (Driver.findelement (By.xpath (XPath)));


6. Combined Mouse Action (drag the target element onto the specified element):
Actions action = new actions (driver);
Action.draganddrop (Driver.findelement (By.xpath (XPath)), Driver.findelement (By.xpath (XPath)));


7. Combined Mouse Action (drag the target element into the specified area):
Actions action = new actions (driver);
Action.draganddrop (Driver.findelement (By.xpath (XPath)), Xoffset,yoffset);


8, the keyboard press operation:
Actions action = new actions (driver);
Action.keydown (Driver.findelement (Getby ()), key); Note: Key is an instance of keys, and a F1 key is instantiated as Keys.f1


9, Button release operation:
Actions action = new actions (driver);
Action.keyup (Driver.findelement (Getby ()), key);

"Reprint" Webdriver commonly used mouse/keyboard operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.