- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 WebDriver 自动上传文件。它适用于 ChromeDriver 和 FirefoxDriver,但不适用于 HTMLUnit。
我已经读过了
Using Webdriver for PrimeFaces file upload
Unable to upload file using Selenium web driver
但是两者都没有帮助。
此上传操作的 selenium (java) 代码非常简单:
String elementXPath = "//input[contains(@id,'FileUpload_input')]";
WebElement element = driver.findElement(By.xpath(elementXPath));
element.sendKeys(pathToFile);
inputElement 的 html 代码是:
<div class="fileupload-buttonbar ui-widget-header ui-corner-top">
<label class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left fileinput-button" role="button" aria-disabled="false">
<span class="ui-button-icon-left ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Upload</span>
<input type="file" id="form:FileUpload_input" name="form:FileUpload_input">
</label>
</div>
<div class="fileupload-content ui-widget-content ui-corner-bottom">
<table class="files"></table>
</div>
也许有必要,输入元素的 primefaces-codesnippet:
<div class="#{modalDialog ? 'span5' : 'span6'}">
<p:fileUpload id="FileUpload" mode="advanced" auto="true" sizeLimit="2097152" fileUploadListener="#{ClassView.handleFileUpload}"
label="Upload" allowTypes="/(\.|\/)(gif|GIF|jpe?g|JPE?G|png|PNG)$/" process="@this"
showButtons="false"/>
</div>
如您所见,这是一张图片上传。此上传的值得注意的特点是,没有“确认”或“提交”按钮。
测试自动化在主浏览器上运行良好,但在 htmlUnit 上失败。经过几个小时的调试,我可以确认 htmlUnit 执行“sendKeys”方法,但这不会触发 fileUploadListener。我已经尝试单击其他元素,因此有一个 focusLost-Action,但这没有帮助。事实上,“sendKeys”之后的“driver.getPageSource()”提供:
<div class="fileupload-buttonbar ui-widget-header ui-corner-top">
<label class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left fileinput-button" role="button" aria-disabled="false">
<span class="ui-button-icon-left ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Upload</span>
<input id="form:FileUpload_input" name="form:FileUpload_input" value="correct\path\to\file\pic.png" type="file" >
</label>
</div>
<div class="fileupload-content ui-widget-content ui-corner-bottom">
<table class="files">
<tbody align="left">
<tr class="template-upload" style="">
<td class="preview"></td>
<td class="name">pic.png</td>
<td class="size"></td>
<td class="progress">
<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="100">
<div class="ui-progressbar-value ui-widget-header ui-corner-left ui-corner-right" style="width: 100%; display: block;"></div>
</div>
</td>
<td class="start">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-state-hover" type="submit">
<span class="ui-button-icon-left ui-icon ui-icon ui-icon-arrowreturnthick-1-n"></span>
<span class="ui-button-text">ui-button</span>
</button>
</td>
<td class="cancel">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
<span class="ui-button-icon-left ui-icon ui-icon ui-icon-cancel"></span>
<span class="ui-button-text">ui-button</span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
所以现在有按钮...为什么?我仍然尝试使用 xPath "//td[@class='start']//button"
单击按钮,但仍然没有发生。没有文件上传。
HtmlDriver 启用了 javascript,而且我正在使用 NicelyResynchronizingAjaxController()。我已经尝试过等待 30 秒以上,但仍然不起作用。
是否有人知道这个问题及其解决方案......或者至少有一个解决方法?
最佳答案
我自己找到了解决方案。我仍在使用 selenium 2.40,升级到 2.42 解决了问题,尽管更新日志没有建议针对我的问题进行可能的错误修复。
关于selenium - 使用 HtmlUnit 的 FileUpload 不会触发 fileUploadListener-Event(Primefaces 自动上传),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25202560/
我需要我的应用程序将输出上传到 pastebin,但我无法让它工作这是代码 WebRequest wr = WebRequest.Create(@"http://pastebin.co
我有一个通过 xmodem 上传文件来完成软件更新的设备。 我能够使用 lrzsz ( http://ohse.de/uwe/software/lrzsz.html) 包以两种方式做到这一点。 1)
我正在使用 React Native Firebase。在 firebase crashlytics,我缺少 DSYM。 在每个构建中自动添加 dSYM 的正确方法是什么?我想它应该被添加到运行脚本?
我在 PHPStorm 的设置中创建了一个新的 Deployment,可以自动上传。工作得很好,我只是想知道在哪里可以让 PHPStorm 检查服务器上的文件是否更新,以及何时两个人正在处理同一个文件
你能帮我解决这个问题吗?我想用 PHP 编写程序并使用 Jquery Mobile。我想让它从设备的相机中拍摄照片。 我可以使用什么方法或功能?一个 php 库还是什么? 最佳答案 首先,您在这里提到
我想配置 blob 的策略以删除不必要的条目,并且我准备了带有规则的 JSON,这可以做到这一点。该文件必须通过 Azure 门户上传。 { "rules": [ { "nam
我正在尝试将 Maven 生成的工件上传到 Nexus 托管存储库的过程自动化(就像 Maven 目标一样,它将生成的 jar 上传到 Nexus 中的指定存储库)。这可能吗?在 Nexus 文档中,
您好,您需要使用 python 和 api(apitoken/apikey) 自动上传 Bugsense proguard 映射文件。我正在尝试使用来自(“github.com/PanosJee/50
我正在尝试使用 WebDriver 自动上传文件。它适用于 ChromeDriver 和 FirefoxDriver,但不适用于 HTMLUnit。 我已经读过了 Using Webdriver fo
我正在使用 Jenkins 和 altool 来验证 iOS 包并自动将其上传到我的 iTunes 帐户。虽然验证工作正常并且我没有收到任何错误,但上传不起作用。 '/Applications/Xco
我是一名优秀的程序员,十分优秀!