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界面的选项菜单需要鼠标悬停在某个元素 ...
随机推荐
- Form_Form Builder中的全局变量和程式变量(概念)
2014-12-20 Created By BaoXinjian
- Intelligence System (hdu 3072 强联通缩点+贪心)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- mysql 怎么给一个表一次增加多个字段, mysql 添加 多个 字段
sql 语句: ALTER TABLE oversea_liveauctioneers_detail_info_2018 ADD `result` LONGTEXT, ADD `buyer_premi ...
- Photoshop制作Android UI: 怎样将图片背景变为透明
看烦了代码.今天玩玩PS吧.本人是PS小白.Android开发中不可避免的要做一些图片,但我发现居然没有相似的专门教程.真想拜个美工为师.还记得2012年去宁波实习时为了将图片缩小我还matlab写个 ...
- NGUI学习笔记(六):ScrollView、Grid和Table
下面我们来看看游戏UI开发中比较核心的开发,我称为列表开发,比如背包和各种形式不一的列表等,下面我们来看几个具体的样例: 基本上就是一些重复的制作好的多个UI控件进行排列,同时可以支持滚动,当然, ...
- 使用自定义验证组件库扩展 Windows 窗体
使用自定义验证组件库扩展 Windows 窗体 1(共 1)对本文的评价是有帮助 - 评价此主题 发布日期 : 8/24/20 ...
- MAC下cmake安装
可以参考网上手动下载cmake的源码包进行安装,http://www.cmake.org/download/ 解压后运行sudo ./bootstrap && sudo make &a ...
- 每日英语:He Diets, She Diets: More Weight-Loss Plans Target Men
Weight-loss companies are becoming savvier about getting men to go on a diet. savvier:更加精明 Men and w ...
- gulp的使用以及Gulp新手入门教程
Gulp新手入门教程 原文 http://w3ctrain.com/2015/12/22/gulp-for-beginners/ Gulp 是一个自动化工具,前端开发者可以使用它来处理常见任务: 搭 ...
- C++面向对象程序设计的一些知识点(2)
1.C++中三种继承方式及派生类中访问控制规则 (1).C++支持的三种继承方式是public.protected.private.C++允许一个类同时以不同的方式对不同的基类加以继承. (2). 不 ...