[英]How to handle <p:fileUpload auto=“true”> with Selenium?
I am using Primeface's (6.1.1) p:fileUpload component with auto="true". 我正在使用带有auto =“ true”的Primeface(6.1.1)p:fileUpload组件。 I did not yet find a solution to upload a file with Selenium (3.14.0). 我尚未找到使用Selenium(3.14.0)上传文件的解决方案。
The xhtml code looks like this: xhtml代码如下所示:
<p:fileUpload id="myUpload" mode="advanced" auto="true"...>
The generated html code looks like this: 生成的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>
I found solutions for auto="false" but not for auto="true". 我找到了auto =“ false”的解决方案,但没有找到auto =“ true”的解决方案。 I tried to send the file path to the input element: 我试图将文件路径发送到输入元素:
WebElement element = driver.findElement(By.id("...myUpload_input"));
new Actions(driver).sendKeys(element, mypath).perform();
But this was obviously not enough, even when appending the RETURN key. 但是,即使添加RETURN键,这显然还是不够的。
I am really stuck here. 我真的被困在这里。 How can this be done? 如何才能做到这一点?
Thanks in advance! 提前致谢!
@kopfarzt did you try the traditional way: @kopfarzt您是否尝试过传统方式:
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
uploadElement.sendKeys("C:\\newhtml.html");
Try below code 试试下面的代码
public class Test{
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
String baseUrl = "url";
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
// enter the file path onto the file-selection input field
uploadElement.sendKeys("C:\\newhtml.html");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.