1. Need to AutoIt tools and Robot class,: https://www.autoitscript.com/site/autoit/downloads/
The use of 2.autoit is no longer explained in detail. Such as:
3. After identifying the Save window, write the script with the AutoIt editor
Controlfocus ("Save Picture", "", "Edit1"); Controlfocus ("title", "Text", ControlID) Edit1=edit instance 1WinWait ("[CLASS: #32770]", "", "Ten) Controlsettext (" Save Picture ", "", "Edit1", "D:\autoit-v3-setup1.png") Sleep (Controlclick) ("Save Picture", "", "Button1");
Save As Au3 file, then aut2exe to EXE, call in Java program
4. The code is as follows
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 creation time: July 1, 2015 5:00:31 * class Description */public class TESTYANZM {Webdriver Dr = null; @Testpublic void Testf () throws AWT Exception, interruptedexception {system.setproperty ("Webdriver.ie.driver", "d:/baiduyundownload/selenium/ IEDriverServer.exe ");d r = new Internetexplorerdriver ();d r.manage (). window (). Maximize ();d R.get (" http:// 172.16.30.209:5555/register.shtml "); Actions action = new actions (DR); Action.contextclick ();//Right-click in the position where you are currently staying Action.contextclick (Dr.findelement (By.id ("codeimg")). Build (). Perform (); Robot Robot = new Robot (); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); Robot.keypress (keyevent. Vk_down); Thread.Sleep (+); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); robot.keypress (Keyevent.vk_down); Thread.Sleep (+); Robot.keyrelease (Keyevent.vk_down); Thread.Sleep (+); 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 !");}}}
Using selenium to save a file with right-click saving