方案如下:

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. DOM window的事件和方法; Rails查询语法query(查询结构继承); turbolinks的局限;

    window.innerHeight 是浏览器窗口可用的高度. window.outerHeight 是浏览器窗口最大的高度. 打开chrome-inspector,上下移动inspector,看到s ...

  2. 基于Oracle的SQL优化(崔华著)-学习笔记

    201704171025 01. 列rows记录的就是执行计划中每一个执行步骤所对应的Cardinality的值 列Cost(%CPU)记录的就是执行计划中的每一个执行步骤对应的成本 02. Comp ...

  3. VS2017 IDE中发布自包含(SCD)DotNET Core项目

    根据Stack Overflow上的一个回答得知,这项功能目前VS2017并不具备,但你可以通过如下方法发布自包含项目: 1.项目文件(.csproj)中添加RuntimeIdentifier配置项, ...

  4. Virtualbox安装Windows 8.1遇到0x000000C4错误解决办法 - 转

    想要尝试一下 Windows 8.1 系统,又不愿意在电脑上直接安装,虚拟机提供了很好的平台.因为平时工作需要,其实电脑上装的虚拟机还是不少的,每天都要开着几个虚拟机一起用.多一个不多,于是尝试在自己 ...

  5. 高级浏览器-SRWare Iron 29.0.1600.0 版本发布

    SRWare Iron是德国一安全公司srware改造的Chrome(铬)命名为铁(iron)的浏览器.于2008年9月18日首次发布. 据官方介绍,Iron浏览器砍掉了Chromium原程序中的很多 ...

  6. 作业要求 20181030-1 Alpha发布用户使用报告

    作业链接[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2325] 队名:二次元梦之队 组长:刘莹莹 组员:周昊 潘世维  王玉潘 赵美增 ...

  7. ASP.NET FORM认证配置排错记录

    搞了2小时都不能实现自动跳转到登录页面,后删除了配置文件中的name,就解决问题了. <authorization>      <deny users="?" / ...

  8. redux-thunk中间件源码

    浅析redux-thunk中间件源码 大多redux的初学者都会使用redux-thunk中间件来处理异步请求,其理解简单使用方便(具体使用可参考官方文档).我自己其实也一直在用,最近偶然发现其源码只 ...

  9. Yii在window下的安装方法

    首先,在http://www.yiichina.com/上下载yii 然后,配置系统环境变量,在win8下,按win+x,找到系统->高级系统设置->环境变量->path 把php的 ...

  10. 解决使用SecureCRT出现的Generic clipboard failure错误【自己亲身经历】

    2016年11月8日:[解决办法]把金山词霸卸载了 血的教训浪费了好几个小时 相关文章 1.RecureCRT could not get data from the Clipboard 和SAP快捷 ...