【问题标题】:How to get the list of enumerated certificates in a windows security dialog如何在 Windows 安全对话框中获取枚举证书列表
【发布时间】:2012-05-19 16:03:03
【问题描述】:

我正在尝试自动化测试,该测试涉及通过智能卡对网站进行身份验证。

我正在使用 c#,Windows 7。

当我启动 url 时,会出现一个 windows security 窗口,要求我从可用证书列表中选择一个证书。

我发现不可能想出一种方法来以编程方式遍历安全对话框中列出的证书列表。我只需要遍历列表并继续阅读列出的证书的友好名称,直到找到与所需证书匹配的证书。

【问题讨论】:

    标签: c# winapi windows-7 automation ui-automation


    【解决方案1】:
    AutomationElementCollection windows =  AutomationElement.RootElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
            foreach (AutomationElement window in windows)
            {
                if (window.Current.ClassName.Equals("#32770"))   //security dialog
                {
                    AutomationElementCollection certs = window.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.ListItem));
                    foreach (AutomationElement cert in certs)
                    {
                        Console.WriteLine(cert.Current.Name);
                    }
                }
            }
    

    【讨论】:

    • 这是一个很好的解决方案,但我在 Windows 10 上遇到了问题。与以前的 Windows 8 或 7 相比,证书的 Windows 安全对话框似乎不同(IE11,而不是边缘)。我获取窗口的完整列表并输出它,没有类名为#32770 的窗口。任何人都知道如何找到适用于 Windows 10 的此对话框?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 2010-09-11
    相关资源
    最近更新 更多