InvalidArgumentException Thrown Even Though Files are Uploaded in <input type='file'> Tag in Selenium-Java

huangapple 未分类评论47阅读模式
英文:

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 &lt;input type=&#39;file&#39;&gt; 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(&quot;user.dir&quot;) + invoiceFilePath + fileNames[0]
						+ &quot;\n&quot;
						+ System.getProperty(&quot;user.dir&quot;) + 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.

&lt;span class=&quot;w-upload-file__pseudo-button-span relative &quot;&gt;Choose Files&lt;/span&gt;
    &lt;div class=&quot;w-u-f__abs-button-wrapper &quot;&gt;&lt;span class=&quot;w-upload-file__pseudo-button-span relative &quot;&gt;Choose Files&lt;/span&gt;&lt;/div&gt;
    &lt;span class=&quot;w-upload-file__span&quot; type=&quot;text&quot; disabled=&quot;&quot;&gt;No file selected&lt;/span&gt;
    &lt;span class=&quot;w-upload-file__input-focus-wrapper&quot;&gt;&lt;/span&gt;
    &lt;div class=&quot;w-upload-file__dropzone-container&quot; tabindex=&quot;0&quot; aria-disabled=&quot;false&quot;&gt;&lt;input type=&quot;file&quot; multiple=&quot;&quot; autocomplete=&quot;off&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;
    &lt;input type=&quot;file&quot; multiple=&quot;&quot; autocomplete=&quot;off&quot; style=&quot;display: none;&quot;&gt;
    &lt;input type=&quot;button&quot; pseudo=&quot;-webkit-file-upload-button&quot; value=&quot;Choose Files&quot;&gt;
    &lt;input type=&quot;file&quot; multiple=&quot;&quot; autocomplete=&quot;off&quot; style=&quot;display: none;&quot;&gt;
    &lt;div class=&quot;w-upload-file__dropzone-container&quot; tabindex=&quot;0&quot; aria-disabled=&quot;false&quot;&gt;&lt;input type=&quot;file&quot; multiple=&quot;&quot; autocomplete=&quot;off&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;

Xpath of "fileSelectionBox" is &quot;//span[contains(text(), &#39;No file selected&#39;)]/preceding::input[@type=&#39;file&#39;]&quot;

I need to get rid of this exception.
Any idea on this?

huangapple
  • 本文由 发表于 2020年5月5日 22:07:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/61615066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定