private string GetCurrentChromeUrl() { try { string url = null; int handle = GetForegroundWindow(); AutomationElement elm = AutomationElement.FromHandle((IntPtr)handle); AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar")); if (elmUrlBar != null) { AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns(); if (patterns.Length > 0) { ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]); url = val.Current.Value; //break; } } return url; } catch (Exception e1) { return ""; } }
AutomationElement elm = AutomationElement.FromHandle((IntPtr)handle);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)