selenium测试(Java)--鼠标事件(六)
鼠标操作:
1.右击
2.双击
3.拖到
4.悬停
![](https://common.cnblogs.com/images/copycode.gif)
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 }
![](https://common.cnblogs.com/images/copycode.gif)
注: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 count() 方法
描述 count() 方法用于统计字符串中某个子字符串出现的次数,可选参数为开始搜索与结束搜索的位置索引. 语法 count() 方法语法: S.count(sub[,start=0[,end=len ...
- Spring的@Required注解
该@Required注解适用于bean属性setter方法,并表示受影响的bean属性必须在XML配置文件在配置时进行填充.否则,容器会抛出一个BeanInitializationException异 ...
- 修改ultisnips的默认键
把ultisnips修改和textmate一致. <tab>展开代码,再按<tab>跳转到下一个占位符,<shift+tab>跳转上一个占位符. 在vim配置文件中 ...
- CSS实现超级链接需要通过双击后跳转
超级链接需要双击后跳转如何实现. CSS代码.test3 span { position: relative;}.test3 span a { position: relative;z-index: ...
- SICP-Exercise 1.5
Exercise 1.5. Ben Bitdiddle has invented a test to determine whether the interpreterhe is faced wit ...
- find 命令查找文件大小为xx的文件
K:字节 G:gb 查找当前目录及子目录下大于1G的文件: # find ./ -size +1G -exec ls -lh {} \; 查找当前目录及子目录下大于1G小于20G的文件: # find ...
- VS2010中水晶报表插件下载安装方法
Visual Studio 2010默认不带水晶报表,需要安装一个水晶报表插件,首先下载此插件: http://downloads.businessobjects.com/akdlm/cr4vs201 ...
- AAuto 快速开发win32小程序
AAuto编程语言 AAuto是专用于桌面软件快速开发的新一代混合型编程语言 - 具有动态语言轻便.灵活.快速开发的特性,而且又可以同时支持静态类型开发,象静态语言那样使用.AAuto可以直接支持原 ...
- Dubbo阅读笔记——高级功能
事件处理线程说明 如果事件处理的逻辑能迅速完成,并且不会发起新的IO请求,比如只是在内存中记个标识,则直接在IO线程上处理更快,因为减少了线程池调度. 但如果事件处理逻辑较慢,或者需要发起新的IO请求 ...
- Spring Boot干货系列:(三)启动原理解析
Spring Boot干货系列:(三)启动原理解析 2017-03-13 嘟嘟MD 嘟爷java超神学堂 前言 前面几章我们见识了SpringBoot为我们做的自动配置,确实方便快捷,但是对于新手来说 ...