ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. ActionChains是低层次自动化交互方式,例如鼠标移动,鼠标按钮操做,按键和右键菜单交互 This is useful for doing more complex actions like hover over and drag and drop. 对于执行复杂操做,像悬停,拖拽,拖放等是有用的。css
Generate user actions.产生用户操做 When you call methods for actions on the ActionChains object,the actions are stored in a queue in the ActionChains object.When you call perform(), the events are fired in the order they are queued up. 当你调用ActionChains对象的操做方法时,操做按顺序存储在ActionChains队列中。当调用perform(),事件按顺序被触发。code
ActionChains can be used in a chain pattern:: ActionChains被应用于chain模式orm
menu = driver.find_element_by_css_selector(".nav") hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1") ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform ()
Or actions can be queued up one by one, then performed.:: 或者操做按序排列,而后执行:对象
menu = driver.find_element_by_css_selector(".nav") hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1") actions = ActionChains(driver) actions.move_to_element(menu) actions.click(hidden_submenu) actions.perform()
Either way, the actions are performed in the order they are called, one after another. 无论怎样,这些操做按他们调用顺序一个接一个的执行队列
Methods defined here:事件
enter(self) Context manager so ActionChains can be used in a 'with .. as' statements.ip
exit(self, _type, _value, _traceback)ci
init(self, driver) Creates a new ActionChains.添加一个新ActionsChainselement
:Args:rem
click(self, on_element=None) Clicks an element.点击一个元素
:Args:
click_and_hold(self, on_element=None) Holds down the left mouse button on an element.在一个元素上点击鼠标左键
:Args:
context_click(self, on_element=None) Performs a context-click (right click) on an element.对一个元素执行点击右键操做
:Args:
double_click(self, on_element=None) Double-clicks an element.双击一个元素
:Args:
drag_and_drop(self, source, target) Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.在源元素上点击鼠标左键,而后移动至目标元素并松开鼠标按钮。
:Args:
drag_and_drop_by_offset(self, source, xoffset, yoffset) Holds down the left mouse button on the source element, then moves to the target offset and releases the mouse button.在源元素上点击鼠标左键,而后移动至目标位置并松开鼠标按钮。
:Args:
key_down(self, value, element=None) Sends a key press only, without releasing it. Should only be used with modifier keys (Control, Alt and Shift).按下键盘上的某个键
:Args:
Keys
class.发送key,值在Keys类总定义。Example, pressing ctrl+c::
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
key_up(self, value, element=None) Releases a modifier key.松开按键
:Args:
Example, pressing ctrl+c::
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
move_by_offset(self, xoffset, yoffset) Moving the mouse to an offset from current mouse position.将鼠标从当前位置移动值另外一个位置。
:Args:
move_to_element(self, to_element) Moving the mouse to the middle of an element.移动鼠标到元素中间位置
:Args:
move_to_element_with_offset(self, to_element, xoffset, yoffset) Move the mouse by an offset of the specified element.Offsets are relative to the top-left corner of the element.按指定元素的偏移量移动鼠标。偏移量是相对于元素左上角移动
:Args:
perform(self) Performs all stored actions.执行全部存储的操做
release(self, on_element=None) Releasing a held mouse button on an element.松开元素上的鼠标按钮
:Args:
reset_actions(self) Clears actions that are already stored on the remote end.清除已经存储在远程终端上的操做。
*send_keys(self, keys_to_send) Sends keys to current focused element.发送按键到当前所在元素
:Args:
*send_keys_to_element(self, element, keys_to_send) Sends keys to an element.发送按键到一个元素。
:Args:
Data descriptors defined here:
dict dictionary for instance variables (if defined)
weakref list of weak references to the object (if defined)