WebDriver API——第3部分Action Chains
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(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(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(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.
- 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(value, element=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(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.
- 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_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()
-
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的更多相关文章
- <译>Selenium Python Bindings 6 - WebDriver API
本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...
- webdriver API study
This chapter cover all the interfaces of Selenium WebDriver. Recommended Import Style The API defini ...
- python+selenium自动化软件测试(第2章):WebDriver API
2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...
- Selenium之Action Chains类
Action Chains类常用于模拟鼠标的行为,比如单击,双击,拖拽等行为,使用下面的方法导入Action Chains类 from selenium.webdriver.common.action ...
- 转:python webdriver API 之操作测试对象
一般来说,所有有趣的操作与页面交互都将通过 WebElement 接口,包括上一节中介绍的对象定位,以及本节中需要介绍的常对象操作.webdriver 中比较常用的操作元素的方法有下面几个: cle ...
- Webdriver API (二)
(转载) 1.3 打开测试页面 对页面对测试,首先要打开被测试页面的地址(如:http://www.google.com),web driver 提供的get方法可以打开一个页面: // And no ...
- selenium2(WebDriver) API
selenium2(WebDriver) API 作者:Glen.He出处:http://www.cnblogs.com/puresoul/ 1.1 下载selenium2.0的包 官方downl ...
- Selenium2+Python:Webdriver API速记手册
由于web自动化常常需要控制浏览器行为和操作页面元素,相关函数又比较多,于是再此记下一份Webdriver API查阅文档以备不时之需. 参考:虫师<Selenium2自动化测试实战>,和 ...
- webdriver API中文文档
1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide:http://seleniu ...
随机推荐
- 32、Flask实战第32天:优化json数据的返回
接着上节,我们通过jsonify返回json数据非常方便 ... return jsonify({"code": 400, "message": message ...
- HDU 6336 Matrix from Arrays
Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 ...
- 【图论】The Bottom of a Graph
[POJ2553]The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11182 ...
- 【线段树】洛谷 P3372 【模板】线段树 1
动态开结点线段树板子. #include<cstdio> using namespace std; typedef long long ll; ll sumv[400005],delta[ ...
- vue-cli创建vue项目
原文出处:https://segmentfault.com/a/1190000008922234 第一步 node环境安装 1.1 如果本机没有安装node运行环境,请下载node 安装包进行安装1. ...
- 将springboot配置文件中的值注入到静态变量
SpringBoot配置文件分为.properties和.yml两种格式,根据启动环境的不同获取不同环境的的值. spring中不支持直接注入静态变量值,利用spring的set注入方法注入静态变量 ...
- django邮件相关设置
EMAIL_HOST = 'smtp.mxhichina.com' # 阿里云企业邮箱 EMAIL_HOST_PORT = 25 # 邮箱服务器端口 EMAIL_HOST_USER = '****** ...
- [转] Ext Grid (ExtJs)上的单击以及双击事件
例1: 1.双击 var cb = new Ext.grid.RowSelectionModel({ singleSelect:true //如果值是false,表明可以选择多行:否则只能选择一行 } ...
- Hiho---欧拉图
欧拉路·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho最近在玩一个解密类的游戏,他们需要控制角色在一片原始丛林里面探险,收集道具,并找到最后的宝藏.现 ...
- [典型漏洞分享]一个典型的XSS盲打漏洞可导致全网用户cookie被盗取
偶平时在做安全测试时,一般是以发现问题为主,点到为止,但做安全的同学可能也遇到过这样的问题,当你尝试向开发的同学描述一个漏洞危害怎么怎么样的时候,双方经常会有一种鸡同鸭讲的感觉,甚至他们觉得我们在夸大 ...