FlaUI:无法通过 Python.NET 调用任何 Retry 方法
FlaUI: Unable to call any Retry method through Python.NET
我正在尝试通过 Python.NET (https://github.com/FlaUI/FlaUI/blob/master/src/FlaUI.Core/Tools/Retry.cs) 调用 FlaUI FlaUI.Core.Tools.Retry
class 方法 WhileNull
。但是,我无法弄清楚如何使用 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 中创建了以下代码(应用程序启动正常并且我能够获得主 window),
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>
)。
我正在尝试通过 Python.NET (https://github.com/FlaUI/FlaUI/blob/master/src/FlaUI.Core/Tools/Retry.cs) 调用 FlaUI FlaUI.Core.Tools.Retry
class 方法 WhileNull
。但是,我无法弄清楚如何使用 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 中创建了以下代码(应用程序启动正常并且我能够获得主 window),
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>
)。