英文:
InvalidArgumentException Thrown Even Though Files are Uploaded in <input type='file'> Tag in Selenium-Java
问题
我正在使用Selenium WebDriver和Java来上传两个文件到<input type='file'>
标签中。
我采用了这个帖子中提到的方法。
这是我具体的代码片段。
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(fileSelectionBox))).sendKeys
(System.getProperty("user.dir") + invoiceFilePath + fileNames[0]
+ "\n"
+ System.getProperty("user.dir") + invoiceFilePath + fileNames[1]);
问题是,尽管两个文件已成功上传,并且应用程序流程继续进行,但我仍然从上面提到的代码片段中收到以下异常。
org.openqa.selenium.InvalidArgumentException: 无法选择一个或多个文件。
DOM结构如下。
<span class="w-upload-file__pseudo-button-span relative ">Choose Files</span>
<div class="w-u-f__abs-button-wrapper "><span class="w-upload-file__pseudo-button-span relative ">Choose Files</span></div>
<span class="w-upload-file__span" type="text" disabled="">No file selected</span>
<span class="w-upload-file__input-focus-wrapper"></span>
<div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>
<input type="file" multiple="" autocomplete="off" style="display: none;">
<input type="button" pseudo="-webkit-file-upload-button" value="Choose Files">
<input type="file" multiple="" autocomplete="off" style="display: none;">
<div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>
"fileSelectionBox" 的 XPath 是 "//span[contains(text(), 'No file selected')]/preceding::input[@type='file']"
我需要解决这个异常。对此有什么想法吗?
英文:
I am using Selenium WebDriver and Java to upload two files in a <input type='file'>
tag.
I have adopted the way mentioned in this post.
This is my code snippet, to be specific.
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(fileSelectionBox))).sendKeys
(System.getProperty("user.dir") + invoiceFilePath + fileNames[0]
+ "\n"
+ System.getProperty("user.dir") + invoiceFilePath + fileNames[1]);
The problem is, although the two files are successfully uploaded, and application flow moves forward, I am still getting this exception from the code snippet mentioned above.
> org.openqa.selenium.InvalidArgumentException: One or more files could not be selected.
The DOM looks like this.
<span class="w-upload-file__pseudo-button-span relative ">Choose Files</span>
<div class="w-u-f__abs-button-wrapper "><span class="w-upload-file__pseudo-button-span relative ">Choose Files</span></div>
<span class="w-upload-file__span" type="text" disabled="">No file selected</span>
<span class="w-upload-file__input-focus-wrapper"></span>
<div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>
<input type="file" multiple="" autocomplete="off" style="display: none;">
<input type="button" pseudo="-webkit-file-upload-button" value="Choose Files">
<input type="file" multiple="" autocomplete="off" style="display: none;">
<div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>
Xpath of "fileSelectionBox" is "//span[contains(text(), 'No file selected')]/preceding::input[@type='file']"
I need to get rid of this exception.
Any idea on this?
专注分享java语言的经验与见解,让所有开发者获益!
评论