Webdriver API (三)- actions
Actions类主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作。对于这些操作,使用perform()方法进行执行。
actions类可以完成单一的操作,也可以完成几个操作的组合。
有时在进行页面操作时,需要做一些特殊的操作,比如移动鼠标到某个位置悬停几秒,或是双击,或是拖拽某个元素,这种情况就需要用到actions类了。
一、单一的操作
单一的操作是指鼠标和键盘的一个操作。如鼠标左键按下、弹起或输入一个字符串等。
比如双击:
Actions dclick = new Actions(driver);
dclick.doubleClick(message).build().perform();
WebElement element = dr.findElement(By.id("test"));
WebElement element1 = dr.findElement(By.id("test1"));
element.sendKeys("test");
element1.click;
用Actions类就可以这样实现:
action Actions action=new Actions(driver);
WebElement element=dr.findElement(By.id("test"));
WebElement element1=dr.findElement(By.id("su"));
action.sendKeys(element,"test").perform();
action.moveToElement(element1);
action.click().perform();
看起来用Actions类实现click和sendKeys有点烦索
WebElement source = driver.findElement(By.id("draggable")); 拖拽源对象
WebElement target = driver.findElement(By.id("droppable")); 拖拽目标对象
Actions action= new Actions(driver);
action.dragAndDrop(source, target).perform(); 选中源对象并多拽到目标对象,然后drop(松开鼠标)
上面的拖拽操作也可以像下面濱示的一样把几个操作放一起实现
Action dragAndDrop = Builder.clickAndHold(source) .moveToElement(target ) .release(target ) .build().perform();
其中Builder是action类下面的一个子类
Webdriver API (三)- actions的更多相关文章
- 第4章 Selenium2-java WebDriver API (三)
4.12 上传文件 4.12.1 sendKeys实现上传 html <html> <head> </head> <body> <div ...
- WebDriver API——鼠标及键盘操作Actions
在自动化中我们可能需要用到鼠标或者是键盘操作,在webdriver中是Actions类进行这些操作的. 代码如下: Actions action = new Actions(driver); //-- ...
- Webdriver API (二)
(转载) 1.3 打开测试页面 对页面对测试,首先要打开被测试页面的地址(如:http://www.google.com),web driver 提供的get方法可以打开一个页面: // And no ...
- webdriver API中文文档
1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide:http://seleniu ...
- python+selenium自动化软件测试(第2章):WebDriver API
2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...
- Selenium WebDriver Api 知识梳理
之前一直没有系统的梳理WebDriver Api的相关知识,今天借此机会整理一下. 1.页面元素定位 1.1.8种常用定位方法 # id定位 driver.find_element_by_id() # ...
- 2.28 查看webdriver API
2.28 查看webdriver API(带翻译) 前言 前面都是点点滴滴的介绍selenium的一些api使用方法,那么selenium的api到底有多少呢?本篇就教大家如何去查看seleni ...
- Webdriver API中文版
Webdriver API中文版 1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGui ...
- selenium初识(二)——之webdriver API
配置完的环境之后,我们先来写一个小脚本: # __Author__:"Jim_xie" from selenium import webdriver from time impor ...
- 用JSON-server模拟REST API(三) 进阶使用
用JSON-server模拟REST API(三) 进阶使用 前面演示了如何安装并运行 json server , 和使用第三方库真实化模拟数据 , 下面将展开更多的配置项和数据操作. 目录: 配置项 ...
随机推荐
- POSIX semaphore: sem_open, sem_close, sem_post, sem_wait
http://www.cnblogs.com/BloodAndBone/archive/2011/01/18/1938552.html 一.Posix有名信号灯 1.posix有名信号灯函数 函数se ...
- 什么叫非阻塞io
而一个NIO的实现会有所不同,下面是一个简单的例子: ByteBuffer buffer = ByteBuffer.allocate(48); int bytesRead = inChannel.re ...
- VC程序查错之内存访问异常
作者:langouster 先来看下面这张图,相信很多程序员都见过类似. ---------------------------test1.exe - 应用程序错误------------------ ...
- C++:向函数传递对象(对象、对象指针、对象引用)
3.5.1 使用对象作为函数参数,其方法与传递基本类型的变量相同 //例3.21 使用对象作为函数参数 #include<iostream> using namespace std; ...
- 【翻译】JavaScript中的作用域和声明提前
原文:http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html ===翻译开始=== 你知道下面的JavaScript脚本执 ...
- Java中ArrayList和LinkedList区别
ArrayList和LinkedList的大致区别如下:1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayLis ...
- When you’re nearly 40 and unmarried, and you realize you’re going to be okay
https://medium.com/the-gathering-kind/when-you-re-nearly-40-and-unmarried-and-you-realize-you-re-goi ...
- python判断文件目录是否存在
import os os.path.isfile('test.txt') # 如果不存在就返回False os.path.exists(directory) # 如果目录不存在就返回False o ...
- 自动化:Appium运行成功,取得一个小的胜利
看过乙醇大神的博文,然后又看了一些大神的博文,自己陆陆续续的折腾了一个月,今天上午的时候,appium终于跑起来了.纪念下,在自动化路上取得的一个小胜利 Appium版本:1.2 Python版本:2 ...
- add-two-numbers-ii
注意:有一种好的方法,是将链表倒转,然后依次相加. 但是,按照题目要求,用了不改变原链表的方法. 就是将两个链表增加到相同长度,然后递归相加,子函数返回后处理进位. https://leetcode. ...