Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Need help with a project StackOverflow TEAM, is for a University project! I need to get all urls from all the tabs opened in Chrome to an C# forms application. Then all the urls, strings, will be load to a listbox... Currently, I'm trying to use System.Windows.Automation.

The main objective of the project is to get all images opened in Chrome, that's why i'm trying this approach, because I need the urls first.

What I have tried:

Process[] procsChrome = Process.GetProcessesByName("chrome");

foreach (Process chrome in procsChrome) {
// the chrome process must have a window
if (chrome.MainWindowHandle == IntPtr.Zero) {
continue;
}

// find the automation element
AutomationElement elm =
AutomationElement.FromHandle(chrome.MainWindowHandle);
AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "Address and search
bar"));

// if it can be found, get the value from the URL bar
if (elmUrlBar != null) {
AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
if (patterns.Length > 0) {
ValuePattern val =
(ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
Console.WriteLine("Chrome URL found: " + val.Current.Value);
}
}
}

but my chrome is in Portuguese language so I change the "Address and search bar" to my language and only worked for the page titles not for the urls...
Posted
Updated 16-Jan-18 4:49am

1 solution

1) This is not Stack Overflow.
2) This is your homework: We don't do it for you: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
3) I wouldn't try to do it via an app - I'd look into a Chrome extension first as that can access urls / images that are opened a lot more easily - you then just have to find a way for that to communicate with your app. Getting Started: Building a Chrome Extension - Google Chrome[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900