1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| class procedure TChromeHelper.Search(const aText: string);
begin
const ChromeList = TWindow.FindAll(ChromeClass);
if Length(ChromeList) = 0 then Exit;
with UIA do
begin
var ChromeElement :IUIAutomationElement;
var Element :IUIAutomationElement;
var CacheRequest :IUIAutomationCacheRequest;
var Conditions :TArray<IUIAutomationCondition>;
var ValuePattern :IUIAutomationValuePattern;
var InvokePattern :IUIAutomationInvokePattern;
var Pt :UIAutomationClient_TLB.tagPOINT;
var Clickable :integer;
// Recherche un EditControl nommé "Rechercher" avec un FrameworkId vide.
// Dans Chrome, un champ dans une page web aurait un FrameworkId = "Chrome".
SetLength(Conditions, 4);
CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_EditControlTypeId, Conditions[1]);
CreatePropertyCondition(UIA_NamePropertyId, 'Rechercher', Conditions[2]);
CreatePropertyCondition(UIA_FrameworkIdPropertyId, '', Conditions[3]);
CreateAndConditionFromNativeArray(Conditions[1], High(Conditions), Conditions[0]);
CreateCacheRequest(CacheRequest);
CacheRequest.AddPattern(UIA_ValuePatternId);
CacheRequest.AddPattern(UIA_InvokePatternId);
for var Chrome in ChromeList do
if Succeeded(ElementFromHandle(pointer(Chrome), ChromeElement)) and Assigned(ChromeElement) and
Succeeded(ChromeElement.FindFirstBuildCache(TreeScope_Descendants, Conditions[0], CacheRequest, Element)) and Assigned(Element) and
Succeeded(Element.GetClickablePoint(Pt, Clickable)) and boolean(Clickable) and // Est visible (cliquable) ?
Succeeded(Element.GetCachedPattern(UIA_ValuePatternId, IInterface(ValuePattern))) and
Succeeded(Element.GetCachedPattern(UIA_InvokePatternId, IInterface(InvokePattern))) then
begin
ValuePattern.SetValue(aText);
InvokePattern.Invoke;
end;
end;
end; |
Partager