PowerShell使用.NET4.8 FlaUI时找不到AsButton方法求助
我在PowerShell脚本中尝试调用FlaUI的AsButton方法,但运行时提示找不到该方法。该脚本用于打开计算器并依次点击“Five”“Plus”“Nine”“Equals”按钮,最后获取计算结果。
脚本代码如下:
[System.Reflection.Assembly]::LoadFrom("c:\Temp\FlaUI.Core.dll") [System.Reflection.Assembly]::LoadFrom("c:\Temp\FlaUI.UIA3.dll") $calc = [Diagnostics.Process]::Start('calc') #wait for the UI to appear $null = $calc.WaitForInputIdle(5000) sleep -s 2 $calcWindowId = ((Get-Process).where{ $_.MainWindowTitle -eq 'Calculator' })[0].Id $uia = New-Object FlaUI.UIA3.UIA3Automation $cf = $uia.ConditionFactory $btnCondition = $cf.ByControlType('Button') $desktop = $uia.GetDesktop() $calc = $desktop.FindFirstDescendant($uia.ConditionFactory.ByProcessId($calcWindowId)) $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Five'))).AsButton().Click() $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Plus'))).AsButton().Click() $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Nine'))).AsButton().Click() $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Equals'))).AsButton().Click() $calc.FindFirstDescendant($cf.ByAutomationId('CalculatorResults')).Properties.Name.Value
运行后抛出如下异常:
Method invocation failed because [FlaUI.Core.AutomationElements.AutomationElement] does not contain a method named 'AsButton'. At C:\Temp\test2.ps1:15 char:1 + $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Five'))).AsBu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound Method invocation failed because [FlaUI.Core.AutomationElements.AutomationElement] does not contain a method named 'AsButton'. At C:\Temp\test2.ps1:16 char:1 + $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Plus'))).AsBu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound Method invocation failed because [FlaUI.Core.AutomationElements.AutomationElement] does not contain a method named 'AsButton'. At C:\Temp\test2.ps1:17 char:1 + $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Nine'))).AsBu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound Method invocation failed because [FlaUI.Core.AutomationElements.AutomationElement] does not contain a method named 'AsButton'. At C:\Temp\test2.ps1:18 char:1 + $calc.FindFirstDescendant($btnCondition.And($cf.ByName('Equals'))).As ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
我使用的是.NET4.8版本的FlaUI,已添加其他相关DLL,网上有同功能的代码可以正常运行,但我的脚本就是找不到AsButton方法,请问这是什么原因?
内容的提问来源于stack exchange,提问作者StackDos
相关产品推荐
相关产品推荐

