方案如下:

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实现右键另存的更多相关文章

  1. selenium webdriver 右键另存为下载文件(结合robot and autoIt)

    首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...

  2. Selenium WebDriver中一些鼠标和键盘事件的使用

    转自:http://www.ithov.com/linux/133271.shtml 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击 ...

  3. Selenium WebDriver 中鼠标和键盘事件分析及扩展(转)

    本文将总结 Selenium WebDriver 中的一些鼠标和键盘事件的使用,以及组合键的使用,并且将介绍 WebDriver 中没有实现的键盘事件(Keys 枚举中没有列举的按键)的扩展.举例说明 ...

  4. Selenium webdriver 开始

    最早接触的selenium是 selenium IDE,当时是为了准备论文.为了用IDE还下载了Firefox浏览器.后来接触过两个项目都需要selenium,一个采用selenium webdirv ...

  5. 转:总结Selenium WebDriver中一些鼠标和键盘事件的使用

    在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...

  6. Selenium WebDriver 中鼠标和键盘事件分析及扩展[转载]

    原文:http://www.ibm.com/developerworks/cn/java/j-lo-keyboard/ 概念 在使用 Selenium WebDriver 做自动化测试的时候,会经常模 ...

  7. selenium webdriver (python)的基本用法一

    阅在线 AIP 文档:http://selenium.googlecode.com/git/docs/api/py/index.html目录一.selenium+python 环境搭建........ ...

  8. 总结Selenium WebDriver中一些鼠标和键盘事件的使用

    在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...

  9. Selenium WebDriver 中鼠标和键盘事件分析及扩展

    [From] http://www.51testing.com/html/18/631118-861557.html 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和 ...

随机推荐

  1. ddt中的data,unpack,file_data实现数据驱动--数据分离

    ddt:Class decorator for subclasses of ``unittest.TestCase``. -----``unittest.testcase``子类的类修饰器. 首先介绍 ...

  2. app手机端连接tomcat电脑端服务器

    1.你要在电脑端开启并启动tomcat 2.启动nginx,然后需要在nginx中配置好端口号,每一个app的模块端口号是不一样的,需要你进行更改 3.如下图代表app连接的端口: 4.关于sql过滤 ...

  3. 基于Open XML 导出数据到Excel

    数据导出的结果: 步骤1.新建一个Excel 文档,模板根据自己需要设置 步骤2.使用OpenXml  打开Excel 文件 步骤3.点击ReflectCode 功能,生成相应的代码文档 using ...

  4. react拖拽(表格拖拽排序、普通拖拽排序以及树形拖拽排序)

    表格拖拽排序:组件地址:https://reactabular.js.org/#/drag-and-drop 拖动的排序是用React-DnD:React-DnD:http://react-dnd.g ...

  5. windows 实用小工具(截图、进程管理)

    1. 截图 picpick:PicPick-NGWIN,一款全功能的设计工具,包含屏幕截图.图片编辑器.颜色选择器.像素标尺和其它更多的功能 2. 二进制/十六进制 十六进制(二进制)编辑器 3. p ...

  6. NAT 穿透

    /********************************************************************************* * NAT 穿透 * 说明: * ...

  7. c# 添加注册表

  8. 一行能装逼的JavaScript代码的延伸

    前段就是坑,入坑水真深. 先看看一个黑科技, 纳尼,这是什么东西. (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+ ...

  9. swift3.0 创建经典界面的九宫图

    网络上很多例子都是早期的 Object-C的效果,现在用到Swift3.0开发,故把网络上的例子翻译过来,达到基本的效果.可是现在这个还不算很满意,再下次继续进行优化 override func vi ...

  10. 【算法】通过TreeMap理解红黑树

    本文以Java TreeMap为例,从源代码层面,结合详细的图解,剥茧抽丝地讲解红黑树(Red-Black tree)的插入,删除以及由此产生的调整过程. 总体介绍 Java TreeMap实现了So ...