1.需要借住autoit工具和Robot类,下载地址:https://www.autoitscript.com/site/autoit/downloads/

2.autoit的使用不再详细讲解。如下图:

3.识别到保存窗口后,用autoit编辑器编写脚本

ControlFocus("保存图片", "","Edit1")
;ControlFocus("title","text",controlID) Edit1=Edit instance 1 WinWait("[CLASS:#32770]","",10) ControlSetText("保存图片", "", "Edit1", "d:\autoit-v3-setup1.png")
Sleep(2000)
ControlClick("保存图片", "","Button1");

 保存为au3文件,再用D:\autoit3\Aut2Exe\Aut2exe转为为exe,在java程序中调用

4.代码如下

package com.gmsd;

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.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
/**
* @author QiaoJiaofei
* @version 创建时间:2015年7月1日 下午5:00:31
* 类说明
*/
public class Testyanzm {
WebDriver dr = null; @Test
public void testf() throws AWTException, InterruptedException {
System.setProperty("webdriver.ie.driver", "D:/BaiduYunDownload/selenium/IEDriverServer.exe");
dr = new InternetExplorerDriver();
dr.manage().window().maximize();
dr.get("http://172.16.30.209:5555/register.shtml");
Actions action = new Actions(dr);
action.contextClick();// 鼠标右键在当前停留的位置做单击操作
action.contextClick(dr.findElement(By.id("codeimg"))).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_DOWN);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(1000); robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(5000); Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/autoitexe/rightsave.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
} }
}

  

使用selenium实现右键另存为保存文件的更多相关文章

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

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

  2. webdriver高级应用- 右键另存为下载文件

    1.要使用右键另存,需要先按照第三方工具AutoIt: 链接: https://pan.baidu.com/s/12aBBhOOTmyQpH9hukt0XGA 密码: fcdk 2.创建一个名为loa ...

  3. python模拟鼠标键盘操作 GhostMouse tinytask 调用外部脚本或程序 autopy右键另存为

    0.关键实现:程序窗口前置 python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过pyauto实现右键菜单和另存为操作 1.参考 aut ...

  4. Win 7 IE11不能下载文件,右键另存为也不行

    在IE11中不能下载文件,右键另存为也无效. 发现 在IE11中点击“INTERNET选项”后,IE临时文件夹的地址没有显示,大小为0,修改只能让设置在8-8MB,注销再登录后,一切设置无效. 问题就 ...

  5. Selenium实现右键保存图片(Java)

    1.代码 public class SaveImage extends TestCase { private WebDriver driver; private Actions action; pri ...

  6. windows下右键新建md文件

    windows下右键新建md文件 打开注册表 win键+R打开运行对话框, 输入regedit, 打开注册表编辑器. 修改注册表 在磁盘的任意位置新建一个文件, 后缀名为reg, 并写入一下内容 [H ...

  7. 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)

    1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...

  8. Js 直接下载保存文件

    //直接下载保存文件 function Download(filePath) { // 如果中间IFRAME不存在,则添加 if (!document.getElementById("_SA ...

  9. C#中saveFileDialog(另存为)保存图片文件

    弹出另存为提示框保存图片文件: //用户自由选择指定路径保存文件            SaveFileDialog savedialog = new SaveFileDialog();        ...

随机推荐

  1. csharp: Export or Import excel using MyXls,Spire.Xls

    excel 2003 (效果不太理想) using System; using System.Collections.Generic; using System.ComponentModel; usi ...

  2. LGLCalender (价格日历)

    一直未能找到自己想要的日历价格,就算右也不是我想要的,今天自己封装了一个,欢迎各位来查阅,不足的地方请指教 最新代码下载地址https://github.com/liguoliangiOS/LGLCa ...

  3. 默认选中ComboBox的某一项

    如: 让它选中“统计今天”(控件Name为cobListTime) 方法: 1.cobListTime.Text = cobListTime.Items[0].ToString();//默认选中第一个 ...

  4. ahjesus sql手动重新更新ID

    declare cus_cursor cursor scroll for SELECT Id from [dbo].[TLotterySpiderRule] open cus_cursor decla ...

  5. ASP.NET Web API通过ActionFilter来实现缓存

    using System; using System.Collections.Generic; using System.Linq; using System.Threading; using Sys ...

  6. window下从硬盘安装linux系统iso镜像文件的方法

    首先,需要安装grub2win,http://sourceforge.net/projects/grub2win/ 其次,将iso文件放在grub2可识别的分区, 如c:\abc\iso.iso 最后 ...

  7. [mysql] 一次sql耗时高引发报警的分析和处理

    1.现象: 最近两天在每天的凌晨0:15-20分左右收到报警短息,报警内容: JDBC-SQL请求最近三分钟内平均耗时时间过高的报警,监控类型:SQL... 2.分析: 从现象来看 每天凌晨15分,可 ...

  8. storm学习途径

    作者: xumingming | 网址: http://xumingming.sinaapp.com/category/storm/  作者:量子恒道 | 网址:http://blog.linezin ...

  9. Docker: 解决Centos 7中Permission Denied的问题

    当用docker -v挂载volume后,会出现Permission Denied的问题,这有时是因为SeLinux导致的.解决方法如下: chcon -Rt svirt_sandbox_file_t ...

  10. Windows7下Blend for Visual Studio 2012使用问题

    目前开发的系统里很多控件样式和动画比较复杂,应该是之前同事用Blend做的,这种神器不用太浪费了,自己也准备试试. 系统环境Windows7+Visual Studio 2012 1.Windows7 ...