gpt4 book ai didi

java - 使用 Selenium 上传 APK 文件

转载 作者:行者123 更新时间:2023-12-02 05:10:53 24 4
gpt4 key购买 nike

我在测试中遇到了一个问题。我正在尝试上传 APK 文件,但是当执行到该步骤时,没有任何反应。

我已经尝试过使用文件路径和 AutoIT 脚本进行简单的 sendKeys,但它们都不起作用。

这里是输入:

<button uib-tooltip-html="uploadTooltip" ng-if="(privileges.update &amp;&amp; !uploadForm.$visible) || createNew" ng-click="this.value = null;" ng-file-select="uploadFile($files, uploadForm)" class="btn btn-xs btn-default ng-scope ng-isolate-scope" ng-disabled="status.disabled || progressPercentage" type="button" style="overflow: hidden;">
<i class="fa fa-fw fa-upload"></i>
<input type="file" tabindex="-1" ng-file-generated-elem="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;">
<input type="file" tabindex="-1" ng-file-generated-elem="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;">
</button>

我尝试过的(也使用带有 sendKeys 完整路径的字符串):

String filePath = System.getProperty("user.dir") + "src\\test\\APK\\com.airbnb.android.apk";
tryToClearAndSendKeysForSeconds(5, UPLOAD_FILE_BUTTON, filePath); // method for sendKeys with wait, locator and string
Runtime.getRuntime().exec("C:\\Users\\IdeaProjects\\Automated_Tests\\src\\test\\APK\\FileUpload.exe");

自动IT:

ControlFocus(“Open”,””,”Edit1″)
ControlSetText(“Open”,””,”Edit1″,”D:\HDimage\profile.jpeg”)
ControlClick(“Open”,””,”Button1″)

我不确定在发送 key 时是否应该在发送文件之前单击上传按钮,但是当我这样做时(顺便说一句,我使用的是 win 10): enter image description here

非常感谢任何帮助!

最佳答案

请按照步骤上传 APK 或任何文件:

a) 将文件上传到服务器上的 tmp 目录中以进行临时备份。就像

String path = FILE_UPLOAD_COMMON_PATH + File.separatorChar + file.getName();

try(FileOutputStream fileOutputStream = new FileOutputStream(path)){
fileOutputStream.write(bs); // byte[] bs
}catch(Exception e) {
throw e;
}

b) 现在从 tmp 目录获取并使用驱动程序上传文件,

String path = FILE_UPLOAD_COMMON_PATH + File.separatorChar + file.getName();
driver.findElements(By.id("files")).get(0).sendKeys(path);

愿它能解决您的问题。

关于java - 使用 Selenium 上传 APK 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56326956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com