Python Selenium actionchains Basic operations

Source: Internet
Author: User

The Actionchains class inherits from the object class, but needs to pass in a driver object, which is actionchains (driver)

This class is commonly used to simulate mouse keyboard operations, and its API list is as follows:

Perform () This method performs all stored actions

Click

Click (Self, On_element=none), this method is the mouse click action, the input parameter is an element, you can not enter

Usage: actionchains (Driver). Click (driver.find_element_by_id ("input")

Click and hold

Click_and_hold (self, On_element=none), this method clicks on an element and holds the argument as an element

Right-click

Context_click (self, On_element=none), this method is right-clicking an element and the argument is an element

Double click

Double_click (self, On_element=none), this method is to double-click an element and the argument is an element

Drag and drop (drag an element to another element)

Drag_and_drop (self, source, target), this method drags the source element to the target element with a parameter of two elements

Drag and drop (drag an element to another location)

Drag_and_drop_by_offset (self, source, Xoffset, Yoffset), this method drags a source element to a xoffset, Yoffset, parameter is an element, two numeric distance (required for shaping)

Press one of the keys

Key_down (self, value, Element=none), this method is to press a key such as Ctrl,shift,alt, the parameter is a key and an element (can be empty)

such as analog ctrl+c:actionschains (driver). Key_down (Keys.control). Send_keys (' C '). KEY_UP (Keys.control). Perform ()

Release a button

Key_up (self, value, Element=none), this method is to release a key such as Ctrl,shift,alt, the parameter is a key and an element (can be empty), need and Key_down with

Move the mouse a section of vertical distance

Move_by_offset (self, Xoffset, yoffset), this method moves the mouse to the specified coordinates with a parameter of two values (required for shaping)

Move to an element

Move_to_element (self, to_element), this method moves the mouse to a specified element, and the argument is an element

dri=driver.find_element_by_id (register_dir[' id_username ')
Actionchains (Driver). Move_to_element (DRI). Click ()

Move to an element, use a distance

Move_to_element_with_offset (self, to_element, Xoffset, Yoffset) This method moves the mouse to a specified element, the parameter is an element, and two shaping numbers

Release mouse

Release (self, On_element=none), this method is used for releasing the mouse, and dragging and dropping, etc.

Keyboard input

Send_keys (self, *keys_to_send), this method is to enter a string into an element, the element must first be found

Send_keys_to_element (self, Element, *keys_to_send), this method enters a string into an element, the argument is an element and a string

Python Selenium actionchains Basic operations

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.