简体   繁体   English

使用 Selenium-WebDriver 通过 AutoIt 上传多个文件

[英]Multiple file upload through AutoIt using Selenium-WebDriver

I used AutoIt to automate a single file's upload.我使用 AutoIt 自动上传单个文件。 Now, I am trying to upload multiple files at once.现在,我正在尝试一次上传多个文件 However, no option is serving the purpose.但是,没有任何选择可以达到目的。 Here are some of the ways I tried:以下是我尝试过的一些方法:

  1. Runtime.getRuntime().exec(ARRAY<Filenames>)

  2. Tried passing as one string.尝试作为一个字符串传递。 Through file system manually this is working fine, but while automating displays as Invalid file name:通过手动文件系统,这工作正常,但在自动化时显示为无效文件名:

     Runtime.getRuntime().exec("E:/AutoItScripts/FileUpload.exe" + ""E:\\Images\\business.jpg" "E:\\Images\\nature.jpeg"");

Please provide solutions/recommendations/suggestions to resolve the problem.请提供解决问题的解决方案/建议/建议。

You need to use the required AutoIt script to upload multiple files at once.您需要使用所需的 AutoIt 脚本一次上传多个文件。 Refer the below script for multiple file upload.请参阅以下脚本进行多文件上传。

ControlFocus("Open","","Edit1")
Global $files="",$appendquotes="",$j=2;
IF $cmdLine[0]==1 then
    $files=$CmdLine[1]
 ElseIf $cmdLine[0] > 1 Then
   For $i=1 to $cmdLine[1]
       $appendquotes='"' & $CmdLine[$j] & '"';
       $files=$files & " " & $appendquotes;
       $j=$j+1;
    Next
EndIf
ControlSetText('Open','','Edit1',$files)
ControlClick("Open","","Button1")

Use the below java code for multiple file upload使用下面的java代码进行多文件上传

Runtime.getRuntime().exec(config.getAutoITFileUploadScript() + " " + files.length + " " + fileToUpload);

Here, 1st parameter is .exe file path of the script we have given.这里,第一个参数是我们给出的脚本的 .exe 文件路径。 2nd parameter is the number of files we are going to pass.第二个参数是我们要传递的文件数。 3rd parameter is the path of the files where each file is enclosed in double quotes separated by single space.(ie)第三个参数是文件的路径,其中每个文件用双引号括起来,用一个空格分隔。(即)

"D:\karthika\uploadfiles\SampleJPGImage_5mbmb.jpg" "D:\karthika\uploadfiles\SamplePNGImage_5mbmb.png" "D:\karthika\uploadfiles\samplefile.png" "D:\karthika\uploadfiles\SamplePNGImage_3mbmb.png" "D:\karthika\uploadfiles\img16.jpg" "D:\karthika\uploadfiles\artwork.jpg" "D:\karthika\uploadfiles\image2.jpg" "D:\karthika\uploadfiles\image3.jpg" "D:\karthika\uploadfiles\image5.jpg"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM