Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WinError -2147221008] 尚未调用 CoInitialize #220

Open
210000ling opened this issue Aug 21, 2022 · 0 comments
Open

[WinError -2147221008] 尚未调用 CoInitialize #220

210000ling opened this issue Aug 21, 2022 · 0 comments

Comments

@210000ling
Copy link

一个很奇怪的现象,如果

import uiautomation

写在自定义函数的外面就会报错,如下

[WinError -2147221008] 尚未调用 CoInitialize。
Can not load UIAutomationCore.dll.

1, You may need to install Windows Update KB971513 if your OS is Windows XP, see https://github.com/yinkaisheng/WindowsUpdateKB971513ForIUIAutomation

2, you need to use an UIAutomationInitializerInThread object if use uiautomation in a thread, see demos/uiautomation_in_thread.py

如果写在函数里面就会正常运行。

这里我主要是寻找一个uwp应用的一个按钮,但是这个按钮没有name属性,也没有automationid属性,所以我是通过他的父类找到他的。代码如下:

def biliuwp_flash():

    #很奇怪,如果import写到外面就无法正常执行

    from pydoc import classname

    from unicodedata import name

    import uiautomation

  

    biliuwp = uiautomation.WindowControl(Name="哔哩哔哩 UWP",classname="ApplicationFrameTitleBarWindow")

    tab = biliuwp.TabControl(classname="Microsoft.UI.Xaml.Controls.TabView",AutomationId="tabView")

    flash = tab.GetLastChildControl()

    #TODO:想办法加快点击的速度

    flash.Click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant