UIAutomation无法在Windows 10上使用最新的Edge浏览器 [英] UIAutomation is not working with latest Edge browser on Windows 10
问题描述
大家好,
UIAutomation无法使用最新的Edge浏览器(版本 -
40.15063.0.0)on
Windows 10( Version - 1703,OS Build 15063.138) 。
请查看示例代码并帮助我们解决此问题:
UIAutomation is not working with latest Edge browser (version- 40.15063.0.0) on Windows 10 (Version - 1703, OS Build 15063.138). Kindly see the sample code and help us to solve this issue:
IUIAutomation * pUIAutomation = NULL;
CoInitialize(NULL) ; $
HRESULT hr = CoCreateInstance(__ uuidof(CUIAutomation),NULL,CLSCTX_INPROC_SERVER,__ uuidof(IUIAutomation),(void **)& pUIAutomation);
if(SUCCEEDED( hr)))
{
EnumDesktopWindows(NULL,EnumWindowsProc,0);
}
$
BOOL WINAPI EnumWindowsProc(HWND hWnd,LPARAM lParam)
{
WCHAR wszClass [32];
GetClassName(hWnd,wszClass,ARRAYSIZE(wszClass));
WCHAR wszText [MAX_PATH];
GetWindowText(hWnd,wszText,ARRAYSIZE(wszText));
if(wcscmp(wszClass,L" ApplicationFrameWindow")== 0&&
StrStrI(wszText ,L" Microsoft Edge")!= 0)
{
HRESULT hr = S_OK;
IUIAutomationElement * pEdgeRoot = NULL;
if(SUCCEEDED(hr))
{
hr = pUIAutomation-> ElementFromHandle(hWnd,& pEdgeRoot);
if(SUCCEEDED(hr))
{
VARIANT varProp;
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L" ; Microsoft Edge&q uot;);
IUIAutomationElement * pElement1 = NULL;
IUIAutomationCondition * condition1 = NULL;
hr = pUIAutomation-> CreatePropertyCondition(UIA_NamePropertyId,varProp,& condition1);
if(SUCCEEDED(hr))
{
hr = pEdgeRoot-> FindFirst(TreeScope_Subtree,condition1,& pElement1);
if(SUCCEEDED(hr))
{
VariantClear(& varProp);
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L" TabW indowClass");
IUIAutomationElement * pElement2 = NULL;
IUIAutomationCondition * condition2 = NULL;
hr = pUIAutomation-> CreatePropertyCondition(UIA_ClassNamePropertyId,varProp, & condition2);
if(SUCCEEDED(hr))
{
hr = pElement1-> FindFirst(TreeScope_Descendants,condition2,& pElement2 ); //
pElement2为空
if(SUCCEEDED(hr))
{
VariantClear(& ; varProp);
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L" Internet Explorer_Server");
IUIAutomationElement * pElement3 = NULL ;
IUIAutomationCondition * condition3 = NULL;
hr = pUIAutomation-> CreatePropertyCondition(UIA_ClassNamePropertyId,varProp,& condition3);
if(SUCCEEDED( hr)))
{
hr = pElement2-> FindFirst(TreeScope_Descendants,condition3,& pElement3);
if(SUCCEEDED(hr))
{
VariantClear(& varProp);
BSTR bstrURL;
hr = pElement3-> get_CurrentName(& bstrURL);
if(pElement3!= NULL)
pElement3-> Release();
}
else
VariantClear(& varProp);
if(condition3!= NULL)
condition3 - > Release();
}
其他
VariantClear( & varProp);
if(pElement2!= NULL)
pElement2-> Release();
}
else
VariantClear(& varProp);
if(condition2!= NULL)
condition2-> Release();
}
else
VariantClear(& varProp);
if(pElement1!= NULL)
pElement1- > Release();
}
else
VariantClear(& varProp);
if(condition1!= NULL)
condition1-> Release();
}
else
VariantClear(& varProp);
if(pEdgeRoot!= NULL)
pEdgeRoot-> Release();
< span style ="white-space:pre"> }
}
}
返回TRUE;
}
IUIAutomation* pUIAutomation = NULL;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (void**)&pUIAutomation);
if (SUCCEEDED(hr))
{
EnumDesktopWindows(NULL, EnumWindowsProc, 0);
}
BOOL WINAPI EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
WCHAR wszClass[32];
GetClassName(hWnd, wszClass, ARRAYSIZE(wszClass));
WCHAR wszText[MAX_PATH];
GetWindowText(hWnd, wszText, ARRAYSIZE(wszText));
if (wcscmp(wszClass, L"ApplicationFrameWindow") == 0 &&
StrStrI(wszText, L"Microsoft Edge") != 0)
{
HRESULT hr = S_OK;
IUIAutomationElement *pEdgeRoot = NULL;
if (SUCCEEDED(hr))
{
hr = pUIAutomation->ElementFromHandle(hWnd, &pEdgeRoot);
if (SUCCEEDED(hr))
{
VARIANT varProp;
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L"Microsoft Edge");
IUIAutomationElement* pElement1 = NULL;
IUIAutomationCondition *condition1 = NULL;
hr = pUIAutomation->CreatePropertyCondition(UIA_NamePropertyId, varProp, &condition1);
if (SUCCEEDED(hr))
{
hr = pEdgeRoot->FindFirst(TreeScope_Subtree, condition1, &pElement1);
if (SUCCEEDED(hr))
{
VariantClear(&varProp);
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L"TabWindowClass");
IUIAutomationElement* pElement2 = NULL;
IUIAutomationCondition *condition2 = NULL;
hr = pUIAutomation->CreatePropertyCondition(UIA_ClassNamePropertyId, varProp, &condition2);
if (SUCCEEDED(hr))
{
hr = pElement1->FindFirst(TreeScope_Descendants, condition2, &pElement2); //
pElement2 is null
if (SUCCEEDED(hr))
{
VariantClear(&varProp);
varProp.vt = VT_BSTR;
varProp.bstrVal = SysAllocString(L"Internet Explorer_Server");
IUIAutomationElement* pElement3 = NULL;
IUIAutomationCondition *condition3 = NULL;
hr = pUIAutomation->CreatePropertyCondition(UIA_ClassNamePropertyId, varProp, &condition3);
if (SUCCEEDED(hr))
{
hr = pElement2->FindFirst(TreeScope_Descendants, condition3, &pElement3);
if (SUCCEEDED(hr))
{
VariantClear(&varProp);
BSTR bstrURL;
hr = pElement3->get_CurrentName(&bstrURL);
if (pElement3 != NULL)
pElement3->Release();
}
else
VariantClear(&varProp);
if (condition3 != NULL)
condition3->Release();
}
else
VariantClear(&varProp);
if (pElement2 != NULL)
pElement2->Release();
}
else
VariantClear(&varProp);
if (condition2 != NULL)
condition2->Release();
}
else
VariantClear(&varProp);
if (pElement1 != NULL)
pElement1->Release();
}
else
VariantClear(&varProp);
if (condition1 != NULL)
condition1->Release();
}
else
VariantClear(&varProp);
if (pEdgeRoot != NULL)
pEdgeRoot->Release();
}
}
}
return TRUE;
}
谢谢,
RJ
RJ
推荐答案
你好RVR,
感谢您在此处发帖。
>> UIAutomation无法使用Windows 10上的最新Edge浏览器
>>UIAutomation is not working with latest Edge browser on Windows 10
您的代码是否与其他任何版本的Edge一起使用?抱歉我没有相同的内容与你的版本Edge,我无法测试它。
Did your code work with any other version of Edge? Sorry that I don't have the same version of Edge with yours, I couldn't test it.
根据这个
文档,如果找不到匹配的元素,则返回NULL。
According to this document, NULL is returned if no matching element is found.
您是否尝试过使用
IUIAutomationElement :: FindAll   ;查找满足指定条件的所有UI自动化元素?检查
中是否有您想要的特定元素
IUIAutomationElementArray 。
Have you tried to use IUIAutomationElement::FindAll to find all UI Automation elements that satisfy the specified condition? Check if there has the specific element you want in IUIAutomationElementArray .
最好的问候,
Sera Yu
Best Regards,
Sera Yu
这篇关于UIAutomation无法在Windows 10上使用最新的Edge浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!