首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用FlaUI实现windows保存对话框的自动化

使用FlaUI实现windows保存对话框的自动化
EN

Stack Overflow用户
提问于 2022-10-24 12:25:52
回答 1查看 43关注 0票数 0

我是在我的智囊团,试图自动化我们的测试的Windows对话框。问题是自动化代码在某些机器上工作,但不是全部。它工作在我的本地盒和其他一些,但我们需要使它工作在我们的所有测试机器。有些东西是不一样的,但到目前为止我能看到的是

  • 相同窗口版本
  • 同dotnet --信息

我尝试过的测试代码如下所示

..。

代码语言:javascript
复制
        var app = FlaUI.Core.Application.Launch("FlaUISaveDialog.exe");
        using (var automation = new UIA3Automation())
        {
            var window = app.GetMainWindow(automation);
            var button1 = window.FindFirstDescendant(cf => cf.ByAutomationId("ClickIt"))?.AsButton();
            button1?.Patterns.Invoke.PatternOrDefault.Invoke();
            Thread.Sleep(2400); // Wait for window to appear!
            var dialog = window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Window));
            
            Thread.Sleep(1000);
            var fileNameTextBox = dialog.FindFirstDescendant(e => e.ByAutomationId("1001"));
            fileNameTextBox.Focus();
            fileNameTextBox.Patterns.Value.Pattern.SetValue(resultFile);
            Thread.Sleep(2400);

            //FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);

            var save = dialog.FindFirstChild(e => e.ByAutomationId("1").And(e.ByControlType(ControlType.Button)));
            save.Focus();
            var mousePoint = new Point(save.BoundingRectangle.X + save.BoundingRectangle.Width/2, save.BoundingRectangle.Y + save.BoundingRectangle.Height/2);
            FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);
            //FlaUI.Core.Input.Mouse.Click(mousePoint);
            //save.Patterns.Invoke.Pattern.Invoke();


            Thread.Sleep(2400); // Wait for file save to complete

            Assert.IsTrue(File.Exists(resultFile));
        }
EN

回答 1

Stack Overflow用户

发布于 2022-10-24 13:57:01

在接下来的一天里,我发现似乎是"SetValue“模式看起来起作用了,但并没有改变对话框的实际文件名。

但是移动鼠标,点击并按下面的方式输入实际上是有效的:

代码语言:javascript
复制
        var fileNameTextBox = dialog.FindFirstDescendant(e => e.ByAutomationId("1001"));
        var mousePoint = new Point(fileNameTextBox.BoundingRectangle.X + fileNameTextBox.BoundingRectangle.Width/2, fileNameTextBox.BoundingRectangle.Y + fileNameTextBox.BoundingRectangle.Height/2);
        Thread.Sleep(1000);
        FlaUI.Core.Input.Mouse.MoveTo(mousePoint);
        FlaUI.Core.Input.Mouse.Click(mousePoint);
        Thread.Sleep(1000);
        FlaUI.Core.Input.Keyboard.TypeSimultaneously(VirtualKeyShort.CONTROL, VirtualKeyShort.KEY_A);
        Thread.Sleep(1000);
        FlaUI.Core.Input.Keyboard.Type(resultFile);
        Thread.Sleep(1000);

        FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);

编辑2:我似乎是Windows选项“查看文件扩展名”影响了"SaveFileDialog“的自动化行为。如果我们打开“查看文件扩展名”,"SetValue“模式就会开始工作。关闭启动和"SetValue“停止工作!至少可以说是出乎意料的!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74181075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档