I'm trying to get a URL from Firefox using UI Automation, but it keeps failing.
It worked fine in Chrome. but it doesn't work in Firefox. i think Search Or Enter Address is same 'Address and search bar' in Chrome
#include <Windows.h>
#include <AtlBase.h>
#include <AtlCom.h>
#include <UIAutomation.h>
#include <stdlib.h>
#define UNICODE
int main()
{
CoInitialize(NULL);
HWND hwnd = NULL;
while (true)
{
hwnd = FindWindowEx(0, hwnd, L"MozillaWindowClass", NULL);
if (!hwnd)
break;
if (!IsWindowVisible(hwnd))
continue;
CComQIPtr<IUIAutomation> uia;
if (FAILED(uia.CoCreateInstance(CLSID_CUIAutomation)) || !uia)
break;
CComPtr<IUIAutomationElement> root;
if (FAILED(uia->ElementFromHandle(hwnd, &root)) || !root)
break;
CComPtr<IUIAutomationCondition> condition;
uia->CreatePropertyCondition(UIA_ControlTypePropertyId,
CComVariant(0xC354), &condition);
CComPtr<IUIAutomationElement> edit;
if (FAILED(root->FindFirst(TreeScope_Descendants, condition, &edit))
|| !edit)
continue; //maybe we don't have the right tab, continue...
CComVariant url;
edit->GetCurrentPropertyValue(UIA_ValueValuePropertyId, &url);
MessageBox(0, url.bstrVal, 0, 0);
break;
}
CoUninitialize();
return 0;
}
A blank value is displayed in the message box I want to get Active tab URL