Using selenium to save a file with right-click saving

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.