Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

retrieved control type and control pattern through UIAutomation library are different with shown in UISpy

$
0
0

This issue doesn't happen with all applications, but consistently happen with NotePad.

For example, in UISpy, it shows the control Type  is controlType.document. Text control pattern is listed there and value control pattern isn't available.

Somehow in my code ( C++ unmanaged), the control Type is shown as edit. Value pattern is available and text pattern isn't. The text retrieved from the value pattern is correct and consistent with which is shown in UISpy. I also verified AutomationID and it's correct, the same as shown in UISpy.

This issue doesn't happen in WordPad, MS office word. It works fine with tchem.

Here is some sample code :

the code to check controlTypeID

intresult = 0;

CONTROLTYPEID controlTypeId;

HRESULT hr;

hr = pt.get_CurrentControlType(&controlTypeId);

if(SUCCEEDED(hr))

{

if(NULL != controlTypeId)

{

and the code where I tried to check which control patterns are available.

 

void

getEditInfo(IUIAutomationElement* pParent, wstring &textContent)

{

   

if(pParent == NULL)

       

return;

BOOL isPassword =

false;

HRESULT hr = pParent->get_CurrentIsPassword(&isPassword);

if( SUCCEEDED(hr) && isPassword) {

textContent.append(L

"isPassWord: Yes\n");

std::wcout << L

"isPassWord: Yes\n";

}

AutomationManager *mgr = AutomationManager::getInstance();

IUIAutomation* pAutomation =mgr->getAutomation();

 

 

 

IUIAutomationTextPattern* pTextPattern=NULL;

IUIAutomationValuePattern* pValuePattern=NULL;

IUIAutomationRangeValuePattern* pRangeValuePattern=NULL;

boolisTextPatternAvailable = isPatternAvailable(pParent,UIA_IsTextPatternAvailablePropertyId);

boolisValuePatternAvailable = isPatternAvailable(pParent,UIA_IsValuePatternAvailablePropertyId);

//bool isSpreadsheetPatternAvailable = isPatternAvailable(pParent,UIA_IsSpreadsheetPatternAvailablePropertyId);


//bool isTextChildPatternAvailable = isPatternAvailable(pParent, UIA_IsTextChildPatternAvailablePropertyId);


FLOG(logDEBUG) <<

"TextPattern available : "<< ( isTextPatternAvailable? " Yes ":" No ") ;

FLOG(logDEBUG) <<

"ValuePattern available : "<< ( isValuePatternAvailable? " Yes ":" No ") ;

hr = pParent->GetCurrentPatternAs(UIA_TextPatternId, IID_IUIAutomationTextPattern, (

void**)&pTextPattern);

   

if( SUCCEEDED(hr) && pTextPattern != NULL) {

FLOG(logDEBUG) <<

"GetCurrentPatternAs  IUIAutomationTextPattern succeeded";

getEditInfoFromTextPattern(pTextPattern, textContent);

}

else{

hr = pParent->GetCurrentPatternAs(UIA_ValuePatternId, IID_IUIAutomationValuePattern, (

void**)&pValuePattern);

if( SUCCEEDED(hr) && pValuePattern != NULL) {

BSTR tmpBstr;

HRESULT hr = pValuePattern->get_CurrentValue(&tmpBstr);

if(SUCCEEDED(hr)) {

std::wstring ws(tmpBstr, SysStringLen(tmpBstr));

std::string s;

s.assign(ws.begin(), ws.end());

FLOG(logDEBUG) <<

"Retrieved text from IUIAutomationValuePattern : ***"<< s << "***";

for(inti=0; i<ws.length(); ++i) {

if( ws[i] =='\n')

ws.erase(i,1);

}

textContent.append(L

"fontName: N/A\n");

textContent.append(L

"textContent:"+ws + L"\n");

std::wcout << ws;

SysFreeString(tmpBstr);

tmpBstr = NULL;

}

}

else{

hr = pParent->GetCurrentPatternAs(UIA_RangeValuePatternId, IID_IUIAutomationRangeValuePattern, (

void**)&pRangeValuePattern);

if( SUCCEEDED(hr) && pRangeValuePattern != NULL) {

doubletmpval;

HRESULT hr = pRangeValuePattern->get_CurrentValue(&tmpval);

if(SUCCEEDED(hr)) {

std::wstring ws = std::to_wstring((

longdouble)tmpval);

textContent.append(L

"fontName: N/A\n");

textContent.append(L

"textContent:"+ws + L"\n");

std::wcout << ws;

}

}

}

}

cleanup :

if(pTextPattern!=NULL) pTextPattern->Release();

if(pValuePattern!=NULL) pValuePattern->Release();

if(pRangeValuePattern!=NULL) pRangeValuePattern->Release();

}

Thanks a lot!


Viewing all articles
Browse latest Browse all 585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>