【问题标题】:Multiple file upload through AutoIt using Selenium-WebDriver使用 Selenium-WebDriver 通过 AutoIt 上传多个文件
【发布时间】:2019-09-20 20:18:39
【问题描述】:

我使用 AutoIt 自动上传单个文件。现在,我正在尝试一次上传多个文件。但是,没有任何选择可以达到目的。以下是我尝试的一些方法:

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

  2. 尝试作为一个字符串传递。通过手动文件系统,这工作正常,但在自动显示为无效文件名时:

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

请提供解决方案/建议/建议来解决问题。

【问题讨论】:

  • 您可能需要转义反斜杠和双引号。一些空间也可能有帮助。试试Runtime.getRuntime().exec("E:\\AutoItScripts\\FileUpload.exe" + " \"E:\\Images\\business.jpg\" \"E:\\Images\\nature.jpeg\"");

标签: java windows automation autoit multi-upload


【解决方案1】:

您需要使用所需的 AutoIt 脚本一次上传多个文件。多文件上传参考以下脚本。

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")

使用下面的java代码进行多文件上传

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

这里,第一个参数是我们给出的脚本的 .exe 文件路径。 第二个参数是我们要传递的文件数。 第三个参数是文件的路径,其中每个文件用双引号括起来,由单个空格分隔。(即)

"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"

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 2017-10-02
    • 2013-09-20
    相关资源
    最近更新 更多