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 ...
随机推荐
- 洛谷——P3414 SAC#1 - 组合数
P3414 SAC#1 - 组合数 题目背景 本题由世界上最蒟蒻最辣鸡最撒比的SOL提供. 寂月城网站是完美信息教室的官网.地址:http://191.101.11.174/mgzd . 题目描述 辣 ...
- C++中template的.h文件和.cpp文件的问题
在C++中,用到类模板时,如果类似一般的类声明定义一样,把类声明放在.h文件中,而具体的函数定义放在.cpp文件中的话,会发现编译器会报错.如类似下面代码: //test.h文件 #ifndef TE ...
- ACM的奇计淫巧_bitset优化
什么是bitset bitset 是STL库中的二进制容器,根据C++ reference 的说法,bitset可以看作bool数组,但优化了空间复杂度和时间复杂度,并且可以像整形一样按位与或. 使用 ...
- [BZOJ4815][CQOI2017]小Q的表格(莫比乌斯反演)
4815: [Cqoi2017]小Q的表格 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 832 Solved: 342[Submit][Statu ...
- 【推导】【找规律】【二分】hdu6154 CaoHaha's staff
题意:网格图.给你一个格点多边形的面积,问你最少用多少条边(可以是单位线段或单位对角线),围出这么大的图形. 如果我们得到了用n条边围出的图形的最大面积f(n),那么二分一下就是答案. n为偶数时,显 ...
- 【区间dp】【记忆化搜索】UVALive - 3516 - Exploring Pyramids
f(i,j)=sum(f(i+1,k-1)*f(k,j) | i+2<=k<=j,Si=Sk=Sj). f(i+1,k-1)是划分出第一颗子树,f(k,j)是划分出剩下的子树. #incl ...
- Problem G: 零起点学算法106——首字母变大写
#include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...
- Linux设备模型(总结)
转:http://www.360doc.com/content/11/1219/16/1299815_173418267.shtml 看了一段时间的驱动编程,从LDD3的hello wrod到后来的字 ...
- jstack_查看当前进程及所属线程执行情况
C:\Program Files\Java\jdk1.7.0_45\bin\jstack.exe 1.任务管理器:进程选择PID 2.命令行执行 cd C:\Program Fi ...
- Ubuntu下,清屏等终端常用命令
转自:http://blog.csdn.net/gaojinshan/article/details/9314435 # ctrl + l - 清屏 . cLear# ctrl + c - 终止命令. ...