我正在使用带有auto =“ true”的Primeface(6.1.1)p:fileUpload组件。我尚未找到使用Selenium(3.14.0)上传文件的解决方案。
xhtml代码如下所示:
<p:fileUpload id="myUpload" mode="advanced" auto="true"...>
生成的html代码如下所示:
<div id="myContainer:myUpload" class="ui-fileupload ui-widget ui-fileupload-responsive">
<div class="ui-fileupload-buttonbar ui-widget-header ui-corner-top">
<span class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-choose" tabindex="0" role="button" aria-labelledby="myContainer:myUpload_label">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-plusthick"/>
<span id="myContainer:myUpload_label" class="ui-button-text ui-c">Select File</span>
<input id="myContainer:myUpload_input" name="myContainer:myUpload_input" tabindex="-1" type="file">
</span>
</div>
<div class="ui-fileupload-content ui-widget-content ui-corner-bottom">
<div class="ui-messages ui-widget ui-helper-hidden ui-fileupload-messages">
<div class="ui-messages-error ui-corner-all">
<a class="ui-messages-close" href="#">
<span class="ui-icon ui-icon-close"/>
</a>
<span class="ui-messages-error-icon"/>
<ul/>
</div>
</div>
<div class="ui-fileupload-files">
<div/>
</div>
</div>
</div>
我找到了auto =“ false”的解决方案,但没有找到auto =“ true”的解决方案。我试图将文件路径发送到输入元素:
WebElement element = driver.findElement(By.id("...myUpload_input"));
new Actions(driver).sendKeys(element, mypath).perform();
但是,即使添加RETURN键,这显然还是不够的。
我真的被困在这里。如何才能做到这一点?
提前致谢!
最佳答案
@kopfarzt您是否尝试过传统方式:
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
uploadElement.sendKeys("C:\\newhtml.html");
关于java - 如何使用Selenium处理<p:fileUpload auto =“true”>?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52558959/