I have been designing a program using Visual C# and have came across an issue with making my program interact with web browsers. Basically what I need is to retrieve the URL address from a web browser (Internet Explorer, Firefox, Chrome etc...).
I figured this wouldn't be too difficult of a task, but after days and days of research and tests, it seems almost impossible! Thus far, I have come across this...
Which has the code below:
using NDde.Client;
Class Test
{
public static string GetFirefoxURL()
{
DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
dde.Connect();
string url = dde.Request("URL", int.MaxValue);
dde.Disconnect();
return url;
}
}
Which is perfect for Firefox, but for some reason I cannot get it to work with anything else. I have changed the portion of the code that says "Firefox" to "Iexplore" like I found all over the internet, along with trying other forms of expressing Internet Explorer, and I get the following error:
"Client failed to connect to "IExplorer|WWW_GetWindowInfo", Make sure the server application is running and that it supports the specified service name and topic name pair"
Any help on the issue would be much appreciated as it has become quite a task to figure out.
Here's what I have so far (though Chrome I'm not finding any helpful articles on, other than using FindWindowEx (I don't particularly like that method, personally).
Use parameter "1" instead of "URL" in oDde.Request("URL", int.MaxValue) for IE.
Mourier, thank you for your solution Microsoft UI Automation. Even so it didn't worked for Firefox 41.0, I analysed the Firefox window structure with the little tool "Automation Spy". Then I've changed the search conditions slightly, and it worked perfectly!
And here is the solution for Chromium 48:
Automation Spy shows Firefox window controls structure. The control of type 'edit' with the name 'Search or enter address' holds the url:![Automation Spy](https://i.stack.imgur.com/6S96w.png)
Note: In your .NET project you need 2 references:
WWW_GetWindowInfo is supported in IE and has been since version 3.02 back in the 16 bit days! Works for Firefox and Opera
I believe that Chrome is in fact the odd one out.
I've got no knowledge of how things are beyond those four.
the bese choice is to use selenium webdriver. best and power full api with full premision
Here is a code based on Microsoft UI Automation:
You can use the UI Spy tool to understand the visual hierarchy for all 3 browsers. You may need to adapt things to make sure it really work in your specific cases, but you should get the general idea with these samples.
And an example that dumps all urls for all the 3 types of process (IE, FF, CH) currently running in the system: