在Windows 10家庭版(从Windows 8.1升级)中无法获取在MS-Edge浏览器中打开的页面的url

本文关键字:Windows url MS-Edge 浏览器 获取 家庭版 1升级 | 更新日期: 2023-09-27 18:10:44

我已经尝试了Guy Barker的代码从链接Microsoft Edge:获取窗口URL和标题在Windows 10专业机,它的工作很好。

如果我在Windows 10家庭版(从Windows 8.1升级)机器中尝试了相同的代码,它不起作用,"urlElement"为我返回null。代码没有找到"Internet Explorer_Server"类。但是"Internet Explorer_Server"类发现,而导航使用inspect.exe。

string urlElementClassName = "Internet Explorer_Server";
IUIAutomationCondition conditionUrl = uiAutomation.CreatePropertyCondition(propertyClassName,urlElementClassName);
IUIAutomationElement urlElement = edgeElement.FindFirstBuildCache( TreeScope.TreeScope_Descendants, conditionUrl, cacheRequest);
if(urlElement == null)//true

我已经进一步探索,代码不捕获窗格(Spartan XAML-To-Trident输入路由窗口)节点在windows 10家庭版机器。所以我无法到达"Internet Explorer_Server"类找到URL。

家庭版和专业版操作系统有什么区别吗?如何解决?

感谢

Satheesh

在Windows 10家庭版(从Windows 8.1升级)中无法获取在MS-Edge浏览器中打开的页面的url

试试这个

AutomationElement main = AutomationElement.FromHandle(GetDesktopWindow());
foreach (AutomationElement child in main.FindAll(TreeScope.Children, PropertyCondition.TrueCondition))
{
    AutomationElement window = GetEdgeCommandsWindow(child);
    if (window == null) // not edge
        continue;
    string str = GetEdgeUrl(window);
}

public static AutomationElement GetEdgeCommandsWindow(AutomationElement edgeWindow)
{
    return edgeWindow.FindFirst(TreeScope.Children, new AndCondition(
        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),
        new PropertyCondition(AutomationElement.NameProperty, "Microsoft Edge")));
}
public static string GetEdgeUrl(AutomationElement edgeCommandsWindow)
{
    var adressEditBox = edgeCommandsWindow.FindFirst(TreeScope.Children,
        new PropertyCondition(AutomationElement.AutomationIdProperty, "addressEditBox"));
    return ((TextPattern)adressEditBox.GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(int.MaxValue);
}
public static string GetEdgeTitle(AutomationElement edgeWindow)
{
    var adressEditBox = edgeWindow.FindFirst(TreeScope.Children,
        new PropertyCondition(AutomationElement.AutomationIdProperty, "TitleBar"));
    return adressEditBox.Current.Name;
}