FlaUI:无法通过Python.NET调用任何Retry方法



我正试图通过Python.NET调用FlaUIFlaUI.Core.Tools.Retry类方法WhileNull(https://github.com/FlaUI/FlaUI/blob/master/src/FlaUI.Core/Tools/Retry.cs)。然而,我不知道如何使用System.Func传递方法。

该方法具有以下签名,

public static RetryResult<T> WhileNull<T>(Func<T> checkMethod, TimeSpan? timeout = null, TimeSpan? interval = null, bool throwOnTimeout = false, bool ignoreException = false, string timeoutMessage = null)

以下是我想在Python.NET、中复制的正在工作的C#代码

using FlaUI.Core;
using FlaUI.Core.Conditions;
using FlaUI.Core.Tools;
using FlaUI.Core.Definitions;
using FlaUI.Core.AutomationElements;
using FlaUI.UIA3;
var app = Application.Launch("software.exe");
var mainWindow = app.GetMainWindow(new UIA3Automation());
ConditionFactory cf = new ConditionFactory(new UIA3PropertyLibrary());
Retry.WhileNull(() => mainWindow.FindFirstDescendant(
cf => cf.ByName("Connect")), throwOnTimeout: true);

我在Python.NET中创建了以下代码(应用程序启动正常,我可以获得主窗口(,

import clr
import sys
flaui_core_path = 'C:\path\to\flaui.core\dll'
flaui_uia3_path = 'C:\path\to\flaui.uia3\dll'
interop_uiautomation_path = 'C:\path\to\interop.uiautomationclient\dll'
sys.path.append(flaui_core_path)
clr.AddReference('FlaUI.Core')
sys.path.append(interop_uiautomation_path)
clr.AddReference('Interop.UIAutomationClient')
sys.path.append(flaui_uia3_path)
clr.AddReference('FlaUI.UIA3')
from FlaUI.Core import Application
from FlaUI.Core.AutomationElements import AutomationElement
from FlaUI.Core.Conditions import ConditionFactory, ConditionBase
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
clr.AddReference('System')
import System
app = Application.Launch('software.exe')
main_window = app.GetMainWindow(UIA3Automation())
cf = ConditionFactory(UIA3PropertyLibrary())
def find_first_descendant():
def cf_by_name(cf):
return cf.ByName("Connect")
return main_window.FindFirstDescendant(
System.Func[ConditionFactory, ConditionBase](cf_by_name)
)
Retry.WhileNull(System.Func[AutomationElement](find_first_descendant), throwOnTimeout=True)

上面的代码启动软件。然而,它在进入Retry.WhileNull后抛出以下错误

Traceback (most recent call last):
File ".sample.py", line 30, in <module>
Retry.WhileNull(System.Func[AutomationElement](find_first_descendant), throwOnTimeout=True)
TypeError: No method matches given arguments for WhileNull: (<class 'System.0, Culture=neutral, PublicKeyToken=null]]'>) 

显式提供函数泛型类型参数将起作用:

WhileNull[System.Int32](
System.Func[System.Int32](my_func),
throwOnTimeout=True)

目前,pythonnet只能在直接使用泛型时解析泛型(例如,如果第一个参数是T,而不是Func<T>(。

最新更新