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界面的选项菜单需要鼠标悬停在某个元素 ...
随机推荐
- DBA_实践指南系列1_Oracle Erp R12系统安装Install(案例)
2013-12-01 Created By BaoXinjian
- 使用select函数改进客户端/服务器端程序
一.当我们使用单进程单连接且使用readline修改后的客户端程序,去连接使用readline修改后的服务器端程序,会出现一个有趣的现象,先来看输出: 先运行服务器端,再运行客户端, simba@ub ...
- System V IPC
1.概述 System V IPC共有三种类型:System V消息队列.System V 信号量.System V 共享内存区. System V IPC操作函数如下: 2.key_t键和ftok函 ...
- vue组件值传递之父组件向子组件传递(props)
<template> <div class="hello"> <h1>{{ msg }}</h1> <ul> <l ...
- Java:HttpClient篇,Cookie概述,及其在HttpClient4.2中的应用
1. Cookie 概述 Cookie是什么? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递.Cookie 包含每次用户访问站点时 Web 应用程序都可以读取 ...
- uva 10537 Toll! Revisited(优先队列优化dijstra及变形)
Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...
- 4X4矩阵键盘扫描程序
4X4矩阵键盘扫描: 1. 4根行线的GIO均设为Output,根列线的GIO均设为Input: 2. 4根行线的GIO分别置为0111.1011.1101.1110,读逐一读取列线GIO的值,可确定 ...
- 用rfkill命令管理蓝牙和wifi
rfkill是一个内核级别的管理工具,可以打开和关闭设备的蓝牙和wifi. #列出所有可用设备rfkill list 输出如下:0: phy0: Wireless LAN Soft blocke ...
- Linux虚拟内存系统常用参数说明
1.admin_reserve_kbytes 给有cap_sys_admin权限的用户保留的内存数量,默认值是min(free pages * 3%, 8MB).这些内存是为了给管理员登录和杀死 ...
- ORACLE 新增记录 & 更新记录
开发中偶尔需要新增一条记录或修改一条记录的几个字段,语法中有微妙的区别. 由于不是经常写,久不写就忘记了,而又要重新查找或调试. 新增记录语法: --新增记录(仿照已有表记录)INSERT INTO ...