【问题标题】:file explorer is not getting open to upload a file文件资源管理器未打开以上传文件
【发布时间】:2021-04-20 13:33:12
【问题描述】:

这是我的 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);

我无法打开文件资源管理器,因此无法传递文件路径。

【问题讨论】:

  • 你不应该真的点击按钮吗?像 DriverOperations.getWhenElementVisible(upload).click()?
  • 是的,我也试过了,现在打开了,但无法传递路径并选择文件
  • 通常是input 元素接受上传路径,而不是button 元素。你能提供你正在处理的页面的链接吗?

标签: java selenium filepath


【解决方案1】:

首先,确保文件路径没有引起问题。下面的示例路径:

E:\\Patients_Data\\Patient_One.xml

instead of E://Patients_Data/Patient_One.xml

接下来,

如果您还有一个输入标签和按钮标签(即 UI 中按钮旁边的文本框),请尝试为输入标签调用 sendkeys 方法来设置文件路径。

如果以上两点不能解决您的问题,那么您必须采用以下方法: 单击打开文件上传窗口的按钮,该窗口不是 Web 组件,并且不受 Selenium 支持。使用任何支持原生窗口弹出的第三方工具,如 Autoit、Sikuli


public void depositSingleDocument(String path, String doctype) throws InterruptedException
   {
       DriverOperations.getWhenElementVisible(upload);
       upload.click();

【讨论】:

  • 我尝试了 AutoIt,它成功了。没有任何文本框或输入元素。直接单击按钮并打开文件资源管理器。
  • 是的,没错.. 并非所有上传都可以使用 sendkeys.. 如果上传带有文本框(输入标签),则可以使用 Sendkeys。因此,使用 Autoit、Sikuli 等第三方工具是唯一的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-17
  • 1970-01-01
  • 1970-01-01
  • 2021-06-03
  • 2011-11-14
相关资源
最近更新 更多