I am trying to get the url from a chrome web browser, version 33 - using C#. I have looked at, and tried, different suggestions here on SO - but so far no luck.
Things I have tried: AutomationElement -> Getting the current tab's URL from Google Chrome using C# The "Address and search bar" element can't be found by use of Automation in the 33 version of Chrome web browser. I also tried using TreeWalker and these where the only elements I found:
Horizontal Scroll Bar
Back by small amount
Forward by small amount
Vertical Scroll Bar
Back by small amount
Forward by small amount
"Title of web page..."
System Menu Bar
System
Minimize
Restore
Close
NDde -> Retrieve current URL from C# windows forms application
NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Chrome", "WWW_GetWindowInfo");
dde.Connect();
NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Chrome", "Chrome_OmniboxView");
dde.Connect();
Neither works... can't connect.
FindWindowEx ->
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
public string GetChromeUrl(Process process)
{
IntPtr handle = IntPtr.Zero;
Process[] procsChrome = Process.GetProcessesByName("chrome");
foreach (Process chrome in procsChrome)
{
// the chrome process must have a window
if (chrome.MainWindowHandle == IntPtr.Zero)
{
continue;
} else
{
handle = chrome.MainWindowHandle;
break;
}
}
IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, null, "Address and search bar");
if (urlHandle != IntPtr.Zero)
{
Console.WriteLine("yes!");
}
return "";
}
Doesn't work either...
How far I got
So I have used UI Spy and inspect to look for the name of the omnibox in Chrome 33. In UI spy it can't be found at all, but in inspect I find the "Address and search bar", which has the url value I am after... the question is how do I get hold of that url info?
Any idea?