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)