selenium测试(Java)--鼠标事件(六)
鼠标操作:
1.右击
2.双击
3.拖到
4.悬停

1 package com.test.mouse;
2
3 import java.io.File;
4
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.WebDriver;
7 import org.openqa.selenium.WebElement;
8 import org.openqa.selenium.firefox.FirefoxDriver;
9 import org.openqa.selenium.firefox.FirefoxProfile;
10 import org.openqa.selenium.interactions.Actions;
11
12 public class MouseOperation {
13
14 public static void main(String[] args) {
15 FirefoxProfile profile = new FirefoxProfile(
16 new File("C:\\Users\\XXXX\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\a6xwo0b1.default"));
17 WebDriver driver = new FirefoxDriver(profile);
18
19 driver.get("http://c37.yunpan.360.cn");
20 driver.manage().window().maximize();
21 waitTime(5000);
22
23 driver.findElement(By.xpath("//*[@id='infoPanel']/a[2]")).click();
24 waitTime(3000);
25
26 driver.findElement(By.xpath("//*[@id='tbText']")).click();
27 WebElement testitem = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]"));
28 testitem.click();
29 waitTime(3000);
30
31 // 左击实现(和元素的click类似)
32 Actions action = new Actions(driver);
33 WebElement test1item = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]"));
34 action.click(test1item).perform();
35 waitTime(5000);
36
37 // 返回上一级
38 driver.findElement(By.xpath("//*[@id='crumb']/div/span[1]")).click();
39 waitTime(5000);
40
41 // 双击实现
42 new Actions(driver).doubleClick(driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]"))).perform();
43 waitTime(5000);
44
45 // 返回上一级
46 driver.findElement(By.xpath("//*[@id='crumb']/div/span[1]")).click();
47 waitTime(5000);
48
49 // 悬停 到更多按钮实现
50 new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[@id='topPanel']/ul/li[3]/a"))).perform();
51
52 // 拖动实现
53 driver.findElement(By.xpath("//*[@id='tbPic']")).click();
54 WebElement begin = driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[1]"));
55 WebElement end = driver.findElement(By.xpath("//*[@id='list']/li[2]/div[2]/span[1]"));
56 new Actions(driver).dragAndDrop(begin, end).perform();
57
58 // 右击实现
59 // 这里虽然使用的是元素任然是test1item,但是页面刷新过后需要重新定位
60 // 参考http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp
61 driver.findElement(By.xpath("//*[@id='tbText']")).click();
62 new Actions(driver).contextClick(driver.findElement(By.xpath("//*[@id='list']/li[1]/div[2]/span[2]")))
63 .perform();
64 waitTime(5000);
65
66 driver.findElement(By.xpath("//*[@id='x-yp-3']/ul/li[4]/a/span")).click();
67 waitTime(5000);
68
69 driver.quit();
70
71 }
72
73 static public void waitTime(int time) {
74
75 try {
76 Thread.sleep(time);
77 } catch (InterruptedException e) {
78 // TODO Auto-generated catch block
79 e.printStackTrace();
80 }
81 }
82
83 }

注:perform()的作用是 执行所有Actions中存储的行为。
selenium测试(Java)--鼠标事件(六)的更多相关文章
- Selenium WebDriver 中鼠标事件(全)
Selenium WebDriver 中鼠标事件(全) 鼠标点击操作 鼠标点击事件有以下几种类型: 清单 1. 鼠标左键点击 Actions action = new Actions(driv ...
- Selenium+Java(九)Selenium键盘与鼠标事件
一.键盘事件 ctrl+a driver.findElement(By.id("kw")).sendKeys(Keys.CONTROL, "a"); ctrl+ ...
- python+selenium三:鼠标事件与键盘事件
1.鼠标事件:# 每个模拟事件后需加.perform() 才会执行# context_click() 右击# double_click() 双击# drag_and_drop(source, targ ...
- Selenium WebDriver 中鼠标事件
鼠标点击操作 鼠标点击事件有以下几种类型: 清单 1. 鼠标左键点击 Actions action = new Actions(driver);action.click();// 鼠标左键在当 ...
- selenium 3.0鼠标事件 (java代码)
注意:ActionChains下相关方法在当前的firefox不工作,建议使用谷歌浏览器. public static void main(String[] args) throws Interrup ...
- Selenium WebDriver中鼠标事件
鼠标点击操作 鼠标点击事件有以下几种类型: 清单 1. 鼠标左键点击 Actions action = new Actions(driver);action.click();// 鼠标左键在当 ...
- 【Selenium专题】鼠标键盘事件
引用包来自selenium-java-2.23.1.jar 调用以下代码时,需要引入actions类,以java为例: import org.openqa.selenium.interactions. ...
- Java GUI 鼠标事件
import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.Mou ...
- JAVA之旅(三十一)——JAVA的图形化界面,GUI布局,Frame,GUI事件监听机制,Action事件,鼠标事件
JAVA之旅(三十一)--JAVA的图形化界面,GUI布局,Frame,GUI事件监听机制,Action事件,鼠标事件 有段时间没有更新JAVA了,我们今天来说一下JAVA中的图形化界面,也就是GUI ...
- 自动化测试-8.selenium操作元素之键盘和鼠标事件
前言 在前面的几篇中重点介绍了一些元素的定位方法,定位到元素后,接下来就是需要操作元素了.本篇总结了web页面常用的一些操作元素方法,可以统称为行为事件 有些web界面的选项菜单需要鼠标悬停在某个元素 ...
随机推荐
- python-循环与判断练习题
一.设计这样一个函数,在指定的文件夹上创建10个文本,以数字给它们命名. def text_creation(): path ='D:/study/python3/w/' for name in ra ...
- Python rindex() 方法
描述 Python rindex() 方法返回子字符串最后一次出现在字符串中的索引位置,该方法与rfind() 方法一样,只不过如果子字符串不在字符串中会报一个异常. 语法 rindex() 方法语法 ...
- 数据库分享一: MySQL的Innodb缓存相关优化
无论是对于哪一种数据库来说,缓存技术都是提高数据库性能的关键技术,物理磁盘的访问速度永 远都会与内存的访问速度永远都不是一个数量级的.通过缓存技术无论是在读还是写方面都可以大大提 高数据库整体性能. ...
- VS中一些不常用的快捷键
Ctrl+E,S:将空格以···显示,将tab以→显示 在VS中使用快捷键(Ctrl+E,S),所有代码中的空格都会用小点表示出来,然后...删....不想看就再用一次好了... Ctrl+M,L:快 ...
- ModelSim之tcl自动化仿真
摘要: ModelSim的tcl最大的优势就在于它可以让整个仿真自动运行,免除每次进行各种用户界面控制操作的麻烦.用tcl就可以自动完成建库.映射库到物理目录.编译源代码.启动仿真器.运行仿真等一系列 ...
- svn导出历史版本
svn导出历史某一个版本,有时候想拷贝出项目某个版本的代码,又不希望覆盖现在的代码,需要用到导出历史版本 1.浏览历史版本 鼠标移到项目上右击显示: 2.选择显示日志,出现版本历史记录: 3.选 ...
- 深入讲解Android Property机制
深入讲解Android Property机制 侯亮 1 概述 Android系统(本文以Android 4.4为准)的属性(Property)机制有点儿类似Windows系统的注册表,其中的 ...
- 编译是报error: 'EVNET_COME_TO_FOREGROUND' was not declared in this scope
Compile++ thumb : game_shared <= main.cpp jni/hellocpp/main.cpp: In function 'void Java_org_coco ...
- NOR FLASH驱动程序
NOR NAND接口: RAM-Like,引脚多 引脚少,复用容量: 小 1M 2M 3M ...
- PLSQL Developer新手使用教程(图文教程)
PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能,下面简单的介 ...