通过System.Windows.Automation访问Chrome中的Silverlight窗口

时间:2011-03-23 20:02:26

标签: silverlight google-chrome ui-automation automationelement

这可能是徒劳的,但我想知道是否有人有这方面的经验。

我正在尝试使用 System.Windows.Automation 访问 Google Chrome 中托管的 Silverlight 应用程序(例如, AutomationElement )。

我遇到的问题是Chrome在子进程中托管Silverlight应用。如果我试图找到“Silverlight Control” AutomationElement(通过使用主进程'hWnd),它将失败。

如果我找到Silverlight主机子进程,它没有窗口句柄,如果我尝试使用子进程找到控件'处理它失败。

我知道它在那里......我可以使用Inspect

看到它

Jerkface

但我只能通过在Silverlight应用中点击并在Inspect中导航来找到它。我无法使用AutomationElement.FindFirst或Inspect。从标签窗口向下导航。

就像IE和Firefox中没有看到的窗口和Silverlight插件之间存在脱节,我不知道如何绕过它。

还有其他人能够做到吗?

1 个答案:

答案 0 :(得分:1)

我不确定这在您的实例中是否有帮助,但我遇到了几个需要从外部启用Silverlight通信的实例(需要与Silverlight应用程序通信的Office应用程序AddIns)。我在托管Silverlight应用程序的html页面中使用了javascript作为该通信的桥梁:

    function sendToNav(message) {
        var nav = document.getElementById("Nav");
        nav.content.NavigationPage.HandleScriptedMessage(message);
    }

    function passMessageToHost(message) {
        if (window.external == null) return;

        window.external.HandleScriptedMessage(message);
    }

如果我能提供任何其他信息,请告诉我。希望这对你有用。