Java 如何在Selenium中的多个位置上载文件?
我正在尝试将3个pdf文件依次上传到3个不同的地方。但在我的例子中,只上传了第一个文件。其余部分打开浏览,但文件未上载。只是停留在文件上传表单上。如果在chromedriver中手动单击“取消”,它将继续上载第三个文件,并且出现相同的错误。第二个和第三个文件不会出现在浏览中。但是chromedriver认为他们是依附的。如果我点击“取消”而不是“上传”,测试结果是成功的,没有两个文件。没有错误消息 我试图为每个文件创建一个上传方法。但一切都没有改变 文件附加的HTML代码:Java 如何在Selenium中的多个位置上载文件?,java,selenium,Java,Selenium,我正在尝试将3个pdf文件依次上传到3个不同的地方。但在我的例子中,只上传了第一个文件。其余部分打开浏览,但文件未上载。只是停留在文件上传表单上。如果在chromedriver中手动单击“取消”,它将继续上载第三个文件,并且出现相同的错误。第二个和第三个文件不会出现在浏览中。但是chromedriver认为他们是依附的。如果我点击“取消”而不是“上传”,测试结果是成功的,没有两个文件。没有错误消息 我试图为每个文件创建一个上传方法。但一切都没有改变 文件附加的HTML代码: <div id
<div id="ide5" data-uid="modal:dialog:document-upload-form-panel" data-better-uid="windows-holder:modal:dialog:document-upload-form-panel">
<span class="fileinput-button">
<input type="file" name="files[]" multiple="multiple">
</span>
<input type="button" class="medium-button multiupload-select" name="formContent:documentUploadFormPanel:addFiles" id="ide6" value="Добавить файлы" data-uid="modal:dialog:document-upload-form-panel:add-files" data-better-uid="windows-holder:modal:dialog:document-upload-form-panel:add-files">
<table class="multiupload-files"></table>
</div>
找到了如何修复
上传第二个和第三个文件时,我设置
Thread.sleep(1000)
在每一步请阅读,特别是关于(MCVE)的部分,这将帮助您调试自己的程序并自行解决问题。如果您这样做了,但仍然卡住了,您可以回来发布您的MCVE,您尝试了什么,以及执行结果,包括任何错误消息,以便我们可以更好地帮助您。同时提供该页面和/或相关HTML的链接。你好,thaks,请发表评论。我更新了问题:)
enum docElements{ incomeStatement, gcvp, personalData}
@И("^Сделать: «(.*)»$")
public void loanAssignParameters(docElements docs) throws InterruptedException {
String doc1 = "C:\\Users\\User\\Documents\\Autotest_dev\\client_docs\\file1.pdf",
doc2 = "C:\\Users\\User\\Documents\\Autotest_dev\\client_docs\\file2.pdf",
doc3 = "C:\\Users\\User\\Documents\\Autotest_dev\\client_docs\\file3.pdf";
switch(docs) {
case incomeStatement:
$(By.name("panesContainer:1:paneContent:panesContainer:2:paneContent:consentDocumentsContainer:consentDocuments:1:checked")).shouldBe(visible).click();
$(By.xpath("//div[@data-uid='kz-2sp-1bo-d-personal-information-section-pane:base-product-consent-documents-pane:consent-documents-container:1']/ul/li[3]/a[2]")).click();
$(By.xpath("//div[@data-uid='modal:dialog:document-upload-form-panel']/span/input")).sendKeys(incomeStatementDoc); //first file attached and uploaded
$(By.name("buttonPanel:ok")).click();
break;
case gcvp:
$(By.name("panesContainer:1:paneContent:panesContainer:2:paneContent:consentDocumentsContainer:consentDocuments:2:checked")).shouldBe(visible).click();
$(By.xpath("//div[@data-uid='kz-2sp-1bo-d-personal-information-section-pane:base-product-consent-documents-pane:consent-documents-container:2']/ul/li[3]/a[2]")).click();
$(By.xpath("//div[@data-uid='modal:dialog:document-upload-form-panel']/span/input")).sendKeys(gcvpDoc); //second file not attached
$(By.name("buttonPanel:ok")).click();
break;
case personalData:
$(By.name("panesContainer:1:paneContent:panesContainer:2:paneContent:consentDocumentsContainer:consentDocuments:3:checked")).shouldBe(visible).click();
$(By.xpath("//div[@data-uid='kz-2sp-1bo-d-personal-information-section-pane:base-product-consent-documents-pane:consent-documents-container:3']/ul/li[3]/a[2]")).click();
$(By.xpath("//div[@data-uid='modal:dialog:document-upload-form-panel']/span/input")).sendKeys(personalDataDoc); //third file not attached
$(By.name("buttonPanel:ok")).click();
break;
default:
Assert.fail("Chosen option to go not written in code");
break;
}
}