c# Getting Chrome URL's from all tab

后端 未结 3 943
北海茫月
北海茫月 2021-01-16 06:18

hi i want to get URL from browsers and for chrome i used these and the is not working getting null exception i think chrome has changed something.. getting error on elm4

3条回答
  •  礼貌的吻别
    2021-01-16 06:49

    I solved the same problem recently with System.Windows.Forms.SendKeys Compared to your result - it's 4 times faster, but doesn't work with websites which use ctrl+l hotkey (for example StackOwerflow in edit mode). Depends on your needs :)

     public void WithSendkeys()
        {
            AutomationElement.RootElement
                .FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "Chrome_WidgetWin_1"))
                .SetFocus();
            SendKeys.SendWait("^l");
            var elmUrlBar = AutomationElement.FocusedElement;
            var valuePattern = (ValuePattern) elmUrlBar.GetCurrentPattern(ValuePattern.Pattern);
            Console.WriteLine(valuePattern.Current.Value);
        }
    

提交回复
热议问题