Selenium how to optimize AutoIt file upload?

Source: Internet
Author: User

Selenium optimizing file Uploads

Selenium file upload is defective and can only support input tag upload. It was selenium's mishap, but we thought of solving the problem in a autoit way. But AutoIt is too cumbersome to use.
Here we first use AutoIt to identify the elements, then write the script, then compile the exe executable file, and then use Java code to invoke exe executable file. Does this process seem complicated? And you'll write AutoIt scripts as well.
So the author would like to be able to write Java script directly instead of the original AutoIt script? Later, the author found the AutoIt integration pack. Simply import the AUTOITX package into your project and configure the environment. We can use it directly.
However, as a fixed file upload code, we need to wrap it up. Why is it called fixed file upload code? You will find that most of the file upload elements are consistent when you use the AutoIt element recognition tool to identify the elements of multiple file uploads. So I call it a fixed file upload code. What if we encounter inconsistencies? Then we can write a new file upload method.
In this way we are completely divorced from the AutoIt tool (interface, not actually), we do not need to write AutoIt code, and do not have to compile the EXE to execute the file, do not have to call. Does that make it easy? However, it is worth mentioning that, because there is no good element identification tool, so the element recognition is still not able to get rid of AutoIt.

First prepare the environment:
Selenium: Our MAVEN coverage of the package is quite comprehensive, so our AUTOITX package can be found directly in Maven. Pull the package code as follows:

    <dependency>        <groupId>de.openkeyword</groupId>        <artifactId>autoit</artifactId>        <version>0.1.17</version>    </dependency>

Configure Jacob's environment: After pulling the AUTOITX bag you will find the AUTOITX package will be error, will indicate the lack of files or configuration, this time we need to build up Jacob's environment, because AUTOITX to Jacob has a dependency. We can't go to maven to pull the bag here. Although there is a Jacob package in Maven, the version is too low, and a fatal flaw is that it lacks a DLL file. Without this DLL file, we autoitx still can't get away. At the same time this Jacob's package needs to go to other sites to get (note Be sure to get the version with the supporting DLL file), where the author provides a newer version of jacob-1.18:
: Https://pan.baidu.com/s/1rengNTex1656t-nvBMKxJw Network Password: 9DPA file password: 1124
After the download we will have several files, we need to put the Jacob-1.18-x**.dll file in the JDK Jdk1.8.0_161\jre\bin directory according to our system. The Jacob.jar file is also imported into the project's library.
1. Create a new library directory under the project to copy the Jacob.jar file to the directory.
2. Then right click on the JRE system library Click Build path under Configure Build path
3. Click Add jars to select the Jacob.jar file before you copy to the project.

AUTOITX code in Java
The AUTOITX code in Java is syntactically consistent with AutoIt, but you need to instantiate a Autoitx object before writing, and then use the method in AUTOITX
For example:

    /*     * 调用autoItX包进行文件上传操作     */    public void autoUploadMode(String filePath) {        try {            AutoItX auto=new AutoItX();            auto.winActivate("打开");            auto.ControlSetText("打开", null, "Edit1", filePath);            auto.sleep(1000);            auto.controlClick("打开", null, "Button1");               logger.info(filePath+"文件上传成功");        } catch (Exception e) {            // TODO: handle exception            logger.error(filePath+"文件上传异常"+e.getMessage());            takeScreenShot();        }    }

Selenium how to optimize AutoIt file upload?

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.