【发布时间】:2016-10-13 12:30:30
【问题描述】:
我需要使用 Chromedriver 通过 Selenium WebDriver 上传文档。我已经尝试了所有的 Action 类和 Javascript 的东西,但这些都不起作用。我假设它们不起作用,因为它们依赖按钮作为输入字段,但是,我正在处理的上传按钮不是。它的 HTML 看起来像这样:
<a id="Dialogs_Dialogs_lbAttachUpload" onclick="return ButtonVerifyEnabled(this, ShowFileSelect);" class="SkinButton sbBlue" onmouseover="ButtonHover(this,30);" onmouseout="ButtonLeave(this);" onmousedown="ButtonDown(this,30);" onmouseup="ButtonHover(this,30);" skinheight="30" style="color: white; width: 132px; height: 30px; line-height: 30px; background-position: 0px 0px;" title=""><div class="SkinButtonLeft" style="background-position: 0px 0px;"></div><div class="SkinButtonRight" style="background-position: -4px 0px;"></div>Upload documents</a>
我已实施并运行 AutoIT 和 Sikuli,但这些解决方案的问题是我无法在通过 Jenkins 运行 Selenium 测试时让它们运行。
我最近的尝试是这样的:
WebElement upload = SConfirmOrder.uploadDocuments_btn(driver);
Actions actions = new Actions(driver);
actions.moveToElement(upload);
actions.sendKeys("filepath\\Test PDF.pdf");
运行成功,但实际上没有文件上传。
【问题讨论】: