Right now i'm using this code below to get URL from active tab i chrome browser
/*
* GetUrlInternal
* */
private string GetUrlInternal(IntPtr process) {
string sURL = null;
Process[] procsChrome = Process.GetProcessesByName("chrome");
foreach (Process chrome in procsChrome) {
if (chrome.MainWindowHandle == IntPtr.Zero) {
continue;
}
AutomationElement element = AutomationElement.FromHandle(chrome.MainWindowHandle);
AutomationElement elm1 = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Google Chrome"));
AutomationElement elm2 = TreeWalker.RawViewWalker.GetLastChild(elm1);
AutomationElement elm3 = elm2.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, ""));
AutomationElement elm4 = elm3.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar));
AutomationElement elementx = elm1.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Pasek adresu i wyszukiwania"));
if (!(bool)elementx.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty)) {
sURL = ((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
}
return sURL;
}
This code works as a charm , but there is a delay between read this URL from chrome. It takes from 2 to 4 seconds to get this URL. Does anyone know why? Thanks for any leads...