这是我的 HTML:
<button ng-if="!isIE()" id="UploadedFileBtn" data-ng-click="SelectFile()" title="Browse" text="Browse" style="padding-bottom :5px" class="ng-scope">
<mosaic-icon name="upload" width="20" height="20" class=""><svg class="icon" width="20" height="20"><use xlink:href="#mosaic_icon_upload"></use></svg></mosaic-icon>
</button>
一个按钮用于打开文件浏览器。 这是我的java代码:
public void depositSingleDocument(String path, String doctype) throws InterruptedException
{
DriverOperations.getWhenElementVisible(upload);
upload.sendKeys(path);
我无法打开文件资源管理器,因此无法传递文件路径。
答案 0 :(得分:1)
首先,确保文件路径没有引起问题。下面的示例路径:
E:\\Patients_Data\\Patient_One.xml
instead of E://Patients_Data/Patient_One.xml
接下来,
如果您还有一个 input 标签和 button 标签(即 UI 中按钮旁边的文本框),那么尝试调用 input 标签的 sendkeys 方法来设置文件路径。
如果以上两点都不能解决您的问题,那么您必须采用以下方法: 单击打开文件上传窗口的按钮,该窗口不是 Web 组件且 Selenium 不支持。使用任何支持本地弹出窗口的第三方工具,如 Autoit、Sikuli
public void depositSingleDocument(String path, String doctype) throws InterruptedException
{
DriverOperations.getWhenElementVisible(upload);
upload.click();