无法在 pythonnet 中导入 FlaUI.FlaUI3 库
Unable to import FlaUI.FlaUI3 library in pythonnet
我正在尝试使用 pythonnet
加载 FlaUI
库。该代码能够加载 FlaUI.UIA3.dll
。但是,导入 FlaUI.UIA3
命名空间失败。
这是我的代码,
import clr
import sys
dll_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.core\3.2.0\lib\net45'
dll_path2 = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45'
sys.path.append(dll_path)
clr.AddReference('FlaUI.Core')
sys.path.append(dll_path2)
clr.AddReference('FlaUI.UIA3')
from FlaUI.Core import Application
from FlaUI.Core.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
我收到的错误如下(使用命令 python sample.py
),
Traceback (most recent call last):
File ".\ToadApp.py", line 12, in <module>
from FlaUI.UIA3 import UIA3Automation
ModuleNotFoundError: No module named 'FlaUI.UIA3'; 'FlaUI' is not a package
如果我不包含 FlaUI.UIA3
库,那么我可以使用 Application.Launch('software.exe')
启动应用程序。
这是我的目录的内容,其中包含 FlaUI3.UIA3.dll
、
C:\Users\amit_tendulkar>dir C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3.2.0\lib\net45
Volume in drive C has no label.
Volume Serial Number is 8692-D75E
Directory of C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3.2.0\lib\net45
25-01-2022 22:28 <DIR> .
25-01-2022 22:28 <DIR> ..
17-07-2020 02:05 105,472 FlaUI.UIA3.dll
17-07-2020 02:05 28,095 FlaUI.UIA3.xml
2 File(s) 133,567 bytes
Dotnet 版本(使用 Windows 10),
C:\Users\amit_tendulkar>dotnet --version
6.0.101
看起来 FlaUI.UIA3.dll
依赖于 Interop.UIAutomationClient.dll
。
将代码更新为以下解决了我的问题。
import clr
import sys
flaui_core_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.core\3.2.0\lib\net45'
flaui_uia3_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45'
interop_uiautomation_path = 'C:\Users\amit_tendulkar\.nuget\packages\interop.uiautomationclient\10.18362.0\lib\net45'
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.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
我正在尝试使用 pythonnet
加载 FlaUI
库。该代码能够加载 FlaUI.UIA3.dll
。但是,导入 FlaUI.UIA3
命名空间失败。
这是我的代码,
import clr
import sys
dll_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.core\3.2.0\lib\net45'
dll_path2 = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45'
sys.path.append(dll_path)
clr.AddReference('FlaUI.Core')
sys.path.append(dll_path2)
clr.AddReference('FlaUI.UIA3')
from FlaUI.Core import Application
from FlaUI.Core.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary
我收到的错误如下(使用命令 python sample.py
),
Traceback (most recent call last):
File ".\ToadApp.py", line 12, in <module>
from FlaUI.UIA3 import UIA3Automation
ModuleNotFoundError: No module named 'FlaUI.UIA3'; 'FlaUI' is not a package
如果我不包含 FlaUI.UIA3
库,那么我可以使用 Application.Launch('software.exe')
启动应用程序。
这是我的目录的内容,其中包含 FlaUI3.UIA3.dll
、
C:\Users\amit_tendulkar>dir C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3.2.0\lib\net45
Volume in drive C has no label.
Volume Serial Number is 8692-D75E
Directory of C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3.2.0\lib\net45
25-01-2022 22:28 <DIR> .
25-01-2022 22:28 <DIR> ..
17-07-2020 02:05 105,472 FlaUI.UIA3.dll
17-07-2020 02:05 28,095 FlaUI.UIA3.xml
2 File(s) 133,567 bytes
Dotnet 版本(使用 Windows 10),
C:\Users\amit_tendulkar>dotnet --version
6.0.101
看起来 FlaUI.UIA3.dll
依赖于 Interop.UIAutomationClient.dll
。
将代码更新为以下解决了我的问题。
import clr
import sys
flaui_core_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.core\3.2.0\lib\net45'
flaui_uia3_path = 'C:\Users\amit_tendulkar\.nuget\packages\flaui.uia3\3.2.0\lib\net45'
interop_uiautomation_path = 'C:\Users\amit_tendulkar\.nuget\packages\interop.uiautomationclient\10.18362.0\lib\net45'
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.Conditions import ConditionFactory
from FlaUI.Core.Tools import Retry
from FlaUI.UIA3 import UIA3Automation
from FlaUI.UIA3 import UIA3PropertyLibrary