This project is read-only.

Want firefox address bar text.

Mar 25, 2008 at 8:20 AM
Hello friends I'm a .net developer and in my application I want to capture the URL from the Mozilla firefox. To do so I've used Automation provided in .net framework 3.0 but failed to do so.
While googling I got this product and played with this. After some time I have this code,

Process[] myProcess = Process.GetProcesses();
Process firefox = new Process();
AutomationElement aeBrowser;
foreach (Process p in myProcess)
if (p.ProcessName == "firefox")
firefox = p;
Core.Application a = Core.Application.Attach(firefox);
SearchCriteria sc = SearchCriteria.All;
Window w = a.GetWindow(sc, InitializeOption.NoCache);
ComboBox cb = (ComboBox)w.Get(SearchCriteria.ByControlType(ControlType.ComboBox));

When I execute this code I'm getting error like: "Must specify at least two conditions."
So anyone have any idea about this.
Can anyone provide me sample code for the same problem.
Mar 25, 2008 at 9:10 AM
Okay folks I've changed the searchCriteria to
SearchCriteria sc = SearchCriteria.All.AndByText(firefox.MainWindowTitle);

and I got the firefox window, but now I got null in "cb", means this code can't find any combobox in the firefox window. Now anyone have somthing to show me.
Mar 25, 2008 at 7:06 PM
This is what you need to do.
This is not how white API should be used. But for this release you might have to live with this. This would be fixed in next release.
Window window = Desktop.Instance.Windows().Find(delegate(Window obj) { return obj.Name.StartsWith("TITLE_OF_YOUR_FIREFOX"); });
AutomationElementFinder finder = new AutomationElementFinder(window.AutomationElement);
AutomationElement comboElement = finder.Descendant(SearchCriteria.ByControlType(ControlType.ComboBox).AndByText("Location"));
ValuePattern currentPattern = (ValuePattern) comboElement.GetCurrentPattern(ValuePattern.Pattern);

The reason you cannot do this in the right way:
1. White doesnt have API where by you can find all UIItems. This needs to be added.
2. In firefox all the AutomationElements donot have frameworkid (i.e. WinForm, WPF or Win32). Its empty. So white is not able to create ComboBox object at all. This needs to be fixed in white again. (This is very rare).
3. The combobox doesnt have DropDown buttons unlike the ones in normal win32 app. Again this needs to be fixed.

I am creating an issue to fix it.