The ActionChains implementation,

class selenium.webdriver.common.action_chains.ActionChains(driver)

Bases: object

ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. 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 can be used in a chain pattern:

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.

click(on_element=None)

Clicks an element.

Args:
  • on_element: The element to click. If None, clicks on current mouse position.
click_and_hold(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(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(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(sourcetarget)
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(sourcexoffsetyoffset)
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(valueelement=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.
  • element: The element to send keys. If None, sends a key to current focused element.

Example, pressing ctrl+c:

ActionsChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
key_up(valueelement=None)

Releases a modifier key.

Args:
  • value: The modifier key to send. Values are defined in Keys class.
  • element: The element to send keys. If None, sends a key to current focused element.

Example, pressing ctrl+c:

ActionsChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
move_by_offset(xoffsetyoffset)

Moving the mouse to an offset from current mouse position.

Args:
  • xoffset: X offset to move to, as a positive or negative integer.
  • yoffset: Y offset to move to, as a positive or negative integer.
move_to_element(to_element)

Moving the mouse to the middle of an element.

Args:
  • to_element: The WebElement to move to.
move_to_element_with_offset(to_elementxoffsetyoffset)
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()

Performs all stored actions.

release(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.
send_keys(*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.

send_keys_to_element(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.

WebDriver API——第3部分Action Chains的更多相关文章

  1. <译>Selenium Python Bindings 6 - WebDriver API

    本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...

  2. webdriver API study

    This chapter cover all the interfaces of Selenium WebDriver. Recommended Import Style The API defini ...

  3. python+selenium自动化软件测试(第2章):WebDriver API

    2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...

  4. Selenium之Action Chains类

    Action Chains类常用于模拟鼠标的行为,比如单击,双击,拖拽等行为,使用下面的方法导入Action Chains类 from selenium.webdriver.common.action ...

  5. 转:python webdriver API 之操作测试对象

    一般来说,所有有趣的操作与页面交互都将通过 WebElement 接口,包括上一节中介绍的对象定位,以及本节中需要介绍的常对象操作.webdriver 中比较常用的操作元素的方法有下面几个: cle ...

  6. Webdriver API (二)

    (转载) 1.3 打开测试页面 对页面对测试,首先要打开被测试页面的地址(如:http://www.google.com),web driver 提供的get方法可以打开一个页面: // And no ...

  7. selenium2(WebDriver) API

    selenium2(WebDriver) API 作者:Glen.He出处:http://www.cnblogs.com/puresoul/  1.1  下载selenium2.0的包 官方downl ...

  8. Selenium2+Python:Webdriver API速记手册

    由于web自动化常常需要控制浏览器行为和操作页面元素,相关函数又比较多,于是再此记下一份Webdriver API查阅文档以备不时之需. 参考:虫师<Selenium2自动化测试实战>,和 ...

  9. webdriver API中文文档

    1.1   下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide:http://seleniu ...

随机推荐

  1. Flip Game II -- LeetCode

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  2. JZYZOJ 1388 旅游 状压dp

    http://172.20.6.3/Problem_Show.asp?id=1388   求拓扑排序方案数 状压dp,最开始以为是拓扑排序加数论或者搜索,没想到是状压dp,突然气死.jpg: 完全没有 ...

  3. 【穷竭】POJ3187-Backward Digit Sums

    [思路] 利用杨辉三角形,每一个数字被加的次数等于它在杨辉三角形中对应的那个数字.注意这道题的意思是,最底层是N的全排序,而不是指1..10都可以.生成杨辉三角形的时候第一次我用了二重循环模拟生成,后 ...

  4. 分页器与form表单

    分页器 分页器对象 from django.core.paginator import Paginator Paginator对象: paginator = Paginator(user_list, ...

  5. idea自动生成spring实体

    创建Spring Boot项目 idea创建新项目 File->New->Project选择Spring Initializr默认使用官方的https://start.spring.io/ ...

  6. [转] SSH配置之web.xml

    在项目中总会遇到一些关于加载的优先级问题, 首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 filter 写在 listener 的前面而会先加载 filter. ...

  7. 安装Xampp-配置appche,mysql运行环境遇到的坑

    用php编写的web应用程序,需运行在php的web容器中,其中apache server是一个针对php web容器,它是apache下的开源项目.通常要运行一个web程序,我们还需要安装数据库软件 ...

  8. <摘录>Linux 环境下编译 0.11版本内核 kernel

    系统环境:Fedora 13 + gcc-4.4.5 最近在看<linux内核0.11完全注释>一书,由于书中涉及汇编语言的地方众多,本人在大学时汇编语言学得一塌糊涂,所以实在看不下去了, ...

  9. 通过dbf文件恢复oracle

    可能有些人会由于各种原因经常重装系统,但是系统里面总是有一些比较重要的软件在重装后就不能用了.比如oracle数据库,众所周知数据库如果通过dmp导入导出麻烦不说,还很耗时,特别是像笔者一个数据库就有 ...

  10. Struct2_使用Ajax调用Action方法并返回值

    一.Login.jsp 1.<head>引入jquery: <script type="text/javascript" src="http://aja ...