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. 对于执行复杂操作,像悬停,拖拽,拖放等是有用的。

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(),事件按顺序被触发。

ActionChains can be used in a chain pattern:: ActionChains被应用于chain模式

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.

exit(self, _type, _value, _traceback)

init(self, driver) Creates a new ActionChains.添加一个新ActionsChains

:Args:

  • 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)

转载于:https://my.oschina.net/u/2431775/blog/1036606

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值