本帖最后由 小白龙 于 2025-3-22 05:46 编辑
回复 8# Five66
多谢大佬指导, 确实是哪个问题,
我是想把下面链接的c#函数改为powershell
https://github.com/FlaUI/FlaUI/b ... ilityMethods.cs#L67
现在的问题是, 下面这行C#代码怎样正确改为powershell, 得先把上游问题解决掉- var modalWindows = Retry.WhileEmpty(() => window.ModalWindows, TimeSpan.FromSeconds(1)).Result;
复制代码 下面代码是gpt生成的powershell, 改的不正确- function CloseWindowWithDontSave {
- param($window)
-
- $window.Close()
- [Wait]::UntilInputIsProcessed()
-
- # 获取窗口的模态对话框
- $modalWindows = [Retry]::WhileEmpty({$window.ModalWindows}, [TimeSpan]::FromSeconds(5)).Result
-
- # 查找 "不保存" 按钮
- if ([Tools.OperatingSystem]::IsWindows11()) {
- $dontSaveButton = $modalWindows[0].FindFirstDescendant("SecondaryButton").AsButton()
- } else {
- $dontSaveButton = $modalWindows[0].FindFirstDescendant( { param($cf) $cf.ByAutomationId("CommandButton_7")} ).AsButton()
- }
-
- # 点击 "不保存" 按钮
- $dontSaveButton.Invoke()
- }
复制代码 原C#代码如下:- public static void CloseWindowWithDontSave(Window window)
- {
- window.Close();
- Wait.UntilInputIsProcessed();
- var modalWindows = Retry.WhileEmpty(() => window.ModalWindows, TimeSpan.FromSeconds(1)).Result;
- Button dontSaveButton;
- if (Tools.OperatingSystem.IsWindows11())
- {
- dontSaveButton = modalWindows[0].FindFirstDescendant("SecondaryButton").AsButton();
- }
- else
- {
- dontSaveButton = modalWindows[0].FindFirstDescendant(cf => cf.ByAutomationId("CommandButton_7")).AsButton();
- }
- dontSaveButton.Invoke();
- }
复制代码
|