如何点击处理Chrome""另存为"在LeanFT Tool中使用Java的对话框?

时间:2017-11-16 05:50:33

标签: java automation leanft

使用LeanFT的Java SDK,可以在" Save"上执行点击操作。来自Chrome's "Save As" dialog的按钮?

2 个答案:

答案 0 :(得分:1)

您是否尝试使用Object Identification Tool来识别保存按钮?

在任何情况下,我了解您现在正在使用 Web 技术,然后单击“保存”按钮,然后提示您将文件保存在某个位置。

您有两种选择:

  1. 将Chrome设置为不再询问保存文件的位置;

  2. 使用 STD 技术描述您要点击的保存按钮。

  3. 此类描述的示例:

    Desktop.describe(Window.class, new WindowDescription.Builder()
            .ownedWindow(false)
            .childWindow(false)
            .windowClassRegExp("Chrome_WidgetWin_1")
            .windowTitleRegExp(" Google Chrome").build())
        .describe(Dialog.class, new DialogDescription.Builder()
            .ownedWindow(true)
            .childWindow(false)
            .text("Save As")
            .nativeClass("#32770").build())
        .describe(Button.class, new ButtonDescription.Builder()
            .text("&Save")
            .nativeClass("Button").build());
    

    然后你可以在这个对象上调用.click方法(或取消,等等)。

答案 1 :(得分:-1)

String home = System.getenv("USERPROFILE") + "\\Downloads\\";
String fileName = "xxxxxxxxx.xls";
File file = new File(home + fileName);
if (file.exists()) {
   file.delete();
   System.out.println("Deleted existing CurrentSortRules.xls file if it is already present");
    }
    Window popup = Desktop.describe(Window.class, new WindowDescription.Builder().ownedWindow(false).childWindow(false)
                                .windowClassRegExp("Chrome_WidgetWin_1").windowTitleRegExp(" Google Chrome").build())
                .describe(Dialog.class, new DialogDescription.Builder().ownedWindow(true).childWindow(false)
                        .text("Save As").nativeClass("#32770").build());