Selenium Webdriver——AutoIt和robot实现右键另存
方案如下:
1.selenium 弹出右键菜单
2.robot选择相关菜单
3.调用autoIt实现windows gui另存操作
test case 如下:
1.打开百度(谷歌浏览器)
2.选择百度图片,右键另存为
3.在弹出另存为窗口输入指定路径,单击保存
robot,模拟键盘操作,使用方向键 ↓
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(1000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(1000); robot.keyPress(KeyEvent.VK_ENTER);
autoIt处理另存为窗口
定位保存按钮,使用ControlFocus方法,用于识别Window 窗口。
WinWait() 设置10 秒钟用于等待窗口的显示
定位编辑框(文件名)title是“另存为”,class是Edit ,instance 是1
使用ControlSetText方法输入保存路径,定位保存按钮,使用ControlClick方法单击保存按钮
;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("另存为", "","Edit1") ; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10) Sleep(2000) ; Set the File name text on the Edit field
ControlSetText("另存为","", "Edit1", "D:\save_file.png") Sleep(5000) ; Click on the Open button
ControlClick("另存为", "","Button1");
然后使用autoIt转换为EXE格式的可执行文件
使用java的runTime类调用
Runtime.getRuntime().exec("D:\\savePicture.exe");
全部代码如下(打开百度,右键保存百度图片)
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions; public class savepicture { public static void main(String[] args) throws InterruptedException, AWTException{
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com");
Actions actions=new Actions(driver);
WebElement baidupiuture =driver.findElement(By.xpath(".//*[@id='lg']/img"));
actions.moveToElement(baidupiuture).contextClick().build().perform(); Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(1000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(1000); robot.keyPress(KeyEvent.VK_ENTER); Runtime rn = Runtime.getRuntime();
try{
String str = "D:\\savePicture.exe" ;
rn.exec(str); } catch (Exception e){
System.out.println("Error to run the exe");
}
Thread.sleep(10000);
driver.quit();
}
}
Selenium Webdriver——AutoIt和robot实现右键另存的更多相关文章
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- Selenium WebDriver中一些鼠标和键盘事件的使用
转自:http://www.ithov.com/linux/133271.shtml 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击 ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展(转)
本文将总结 Selenium WebDriver 中的一些鼠标和键盘事件的使用,以及组合键的使用,并且将介绍 WebDriver 中没有实现的键盘事件(Keys 枚举中没有列举的按键)的扩展.举例说明 ...
- Selenium webdriver 开始
最早接触的selenium是 selenium IDE,当时是为了准备论文.为了用IDE还下载了Firefox浏览器.后来接触过两个项目都需要selenium,一个采用selenium webdirv ...
- 转:总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展[转载]
原文:http://www.ibm.com/developerworks/cn/java/j-lo-keyboard/ 概念 在使用 Selenium WebDriver 做自动化测试的时候,会经常模 ...
- selenium webdriver (python)的基本用法一
阅在线 AIP 文档:http://selenium.googlecode.com/git/docs/api/py/index.html目录一.selenium+python 环境搭建........ ...
- 总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展
[From] http://www.51testing.com/html/18/631118-861557.html 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和 ...
随机推荐
- UriComponentsBuilder和UriComponents url编码
Spring MVC 提供了一种机制,可以构造和编码URI -- 使用UriComponentsBuilder和UriComponents. 功能相当于 urlencode()函数,对url进行编码, ...
- Android之第三方平台实现QQ登录和QQ分享
目前大多数APP都包含了第三方平台的登录,特别是QQ和微信,这篇博客主要讲的是如何实现QQ第三方平台实现QQ登录和分享功能,功能包含: 登录授权登录获取用户信息(昵称,头像,地址等) QQ分享给好友 ...
- office-word
目录(大纲) word中大纲的视图(也就是目录)是根据1/2/3级大纲决定的 格式刷 可以刷成一样的格式,字体,编号以及大纲等等. 主要用于编号和目录,快捷键(ctrl+shift) 编号设置(不建议 ...
- 实用性较强的idea插件
1. .ignore 生成各种ignore文件,一键创建git ignore文件的模板,免得自己去写 2. GsonFormat 一键根据json文本生成java类 非常方便 3.Maven Hel ...
- 阅读和设计源码利器UML
https://www.w3cschool.cn/uml_tutorial/ 就不做特殊说明了啊: 一 UML 1 简介 类注释: 下面的图表示的 UML 类,该图被分为四个部分. 顶端部分被用来命名 ...
- Spring的注解@Qualifier(二十五)
转载:https://www.cnblogs.com/smileLuckBoy/p/5801678.html 近期在捯饬spring的注解,现将遇到的问题记录下来,以供遇到同样问题的童鞋解决~ 先说明 ...
- POJ 2251 Dungeon Master bfs 难度:0
http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...
- Java——抽象类、接口
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- STL标准库-容器-deque
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性. deque双向开口可进可出的容器 我们知道连续内存的容器不能随意扩充,因为这样容易扩充别人那去 deque却可以,它创造了内存 ...
- Relation.js——基于pixi.js的拓展模块之人物关系图谱
出于[重构基于D3的关系图谱项目]的目的,在看完pixi.js之后,并且网上又没有现成的基于webgl的关系图谱js库,于是,本人决定自己写一个. 因为平常要工作的原因,进度可能有点慢,但是githu ...