classActionChains(__builtin__.object)

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

  • driver: The WebDriver instance which performs user actions.執行用戶操做的 WebDriver 實例

click(self, on_element=None) Clicks an element.點擊一個元素

:Args:

  • on_element: The element to click. If None, clicks on current mouse position.被點擊的元素,若是爲空,點擊當前鼠標的位置。

click_and_hold(self, on_element=None) Holds down the left mouse button on an element.在一個元素上點擊鼠標左鍵

:Args:

  • on_element: The element to mouse down. If None, clicks on current mouse position.被點擊的元素,若是爲空,點擊當前鼠標的位置。

context_click(self, on_element=None) Performs a context-click (right click) on an element.對一個元素執行點擊右鍵操做

:Args:

  • on_element: The element to context-click. If None, clicks on current mouse position.被點擊的元素,若是爲空,點擊當前鼠標的位置。

double_click(self, on_element=None) Double-clicks an element.雙擊一個元素

:Args:

  • on_element: The element to double-click. If None, clicks on current mouse position.被雙擊的元素,若是爲空,點擊當前鼠標的位置

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:

  • source: The element to mouse down.被按下鼠標的元素
  • target: The element to mouse up.被鬆開鼠標的元素

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:

  • source: The element to mouse down.被按下鼠標的元素
  • xoffset: X offset to move to.水平移動偏移量
  • yoffset: Y offset to move to.垂直移動偏移量

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:

  • value: The modifier key to send. Values are defined in Keys class.發送key,值在Keys類總定義。
  • element: The element to send keys. If None, sends a key to current focused element.發送按鍵元素,若是爲空,發送一個鍵到當前的焦點元素。

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:

  • value: The modifier key to send. Values are defined in Keys class.發送key,值在Keys類總定義。
  • element: The element to send keys. If None, sends a key to current focused element.發送按鍵元素,若是爲空,發送一個鍵到當前的焦點元素。

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:

  • xoffset: X offset to move to, as a positive or negative integer.水平移動偏移量,x可使正整數或負整數。
  • yoffset: Y offset to move to, as a positive or negative integer.垂直移動偏移量,y可使正整數或負整數。

move_to_element(self, to_element) Moving the mouse to the middle of an element.移動鼠標到元素中間位置

:Args:

  • to_element: The WebElement to move to.被移動的元素。

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:

  • to_element: The WebElement to move to.被移動的元素
  • xoffset: X offset to move to.水平移動偏移量
  • yoffset: Y offset to move to.垂直移動偏移量

perform(self) Performs all stored actions.執行全部存儲的操做

release(self, on_element=None) Releasing a held mouse button on an element.鬆開元素上的鼠標按鈕

:Args:

  • on_element: The element to mouse up. If None, releases on current mouse position.被鬆開的鼠標按鈕,若爲空,則爲鼠標當前位置

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:

  • keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class.發送按鍵,keys

*send_keys_to_element(self, element, keys_to_send) Sends keys to an element.發送按鍵到一個元素。

:Args:

  • element: The element to send keys.被髮送按鍵的元素。
  • keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class.被髮送的keys,keys存在於Kyes類中

Data descriptors defined here:

dict dictionary for instance variables (if defined)

weakref list of weak references to the object (if defined)

相關文章
相關標籤/搜索