@@ -202,46 +202,11 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
202202 info[@" label" ] = FBValueOrNull (wrappedSnapshot.wdLabel );
203203 info[@" rect" ] = wrappedSnapshot.wdRect ;
204204
205- // Define the base attribute blocks that apply to all elements.
206- NSDictionary <NSString *, NSString * (^)(void )> *baseAttributeBlocks = @{
207- FBExclusionAttributeFrame: ^{
208- return NSStringFromCGRect(wrappedSnapshot.wdFrame );
209- },
210- FBExclusionAttributeEnabled: ^{
211- return [@([wrappedSnapshot isWDEnabled ]) stringValue ];
212- },
213- FBExclusionAttributeVisible: ^{
214- return [@([wrappedSnapshot isWDVisible ]) stringValue ];
215- },
216- FBExclusionAttributeAccessible: ^{
217- return [@([wrappedSnapshot isWDAccessible ]) stringValue ];
218- },
219- FBExclusionAttributeFocused: ^{
220- return [@([wrappedSnapshot isWDFocused ]) stringValue ];
221- }
222- };
223-
224- NSMutableDictionary <NSString *, NSString *(^)(void )> *attributeBlocks;
225-
226- // Add placeholderValue only for elements where it is meaningful (e.g., text input fields).
227- switch (snapshot.elementType ) {
228- case XCUIElementTypeTextField:
229- case XCUIElementTypeSecureTextField:
230- case XCUIElementTypeSearchField: {
231- // Copy base attributes to a mutable dictionary so we can add placeholderValue.
232- attributeBlocks = [baseAttributeBlocks mutableCopy ];
233- attributeBlocks[FBExclusionAttributePlaceholderValue] = ^{
234- return (NSString *)FBValueOrNull (wrappedSnapshot.wdPlaceholderValue );
235- };
236- break ;
237- }
238- default :
239- // Use the base attributes as-is if placeholderValue is not applicable.
240- attributeBlocks = [baseAttributeBlocks copy ];
241- break ;
242- }
205+ NSMutableDictionary <NSString *, NSString *(^)(void )> *attributeBlocks = [self attributeBlockMapForSnapshot: snapshot
206+ wrappedSnapshot: wrappedSnapshot];
243207
244- NSSet *nonPrefixedKeys = [NSSet setWithObjects: FBExclusionAttributeFrame, FBExclusionAttributePlaceholderValue, nil ];
208+ NSSet *nonPrefixedKeys = [NSSet setWithObjects: FBExclusionAttributeFrame,
209+ FBExclusionAttributePlaceholderValue, nil ];
245210
246211 for (NSString *key in attributeBlocks) {
247212 if (excludedAttributes == nil || ![excludedAttributes containsObject: key]) {
@@ -272,6 +237,41 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
272237 return info;
273238}
274239
240+ // Private helper that builds all attribute blocks for a given snapshot.
241+ // Includes both base attributes and any element-specific ones (e.g. placeholder for text inputs, etc.).
242+ + (NSMutableDictionary <NSString *, NSString *(^)(void)> *)attributeBlockMapForSnapshot : (id <FBXCElementSnapshot>)snapshot
243+ wrappedSnapshot : (FBXCElementSnapshotWrapper *)wrappedSnapshot
244+ {
245+ // Base attributes common to every element
246+ NSMutableDictionary <NSString *, NSString *(^)(void )> *blocks =
247+ [@{
248+ FBExclusionAttributeFrame: ^{
249+ return NSStringFromCGRect(wrappedSnapshot.wdFrame );
250+ },
251+ FBExclusionAttributeEnabled: ^{
252+ return [@([wrappedSnapshot isWDEnabled ]) stringValue ];
253+ },
254+ FBExclusionAttributeVisible: ^{
255+ return [@([wrappedSnapshot isWDVisible ]) stringValue ];
256+ },
257+ FBExclusionAttributeAccessible: ^{
258+ return [@([wrappedSnapshot isWDAccessible ]) stringValue ];
259+ },
260+ FBExclusionAttributeFocused: ^{
261+ return [@([wrappedSnapshot isWDFocused ]) stringValue ];
262+ }
263+ } mutableCopy];
264+
265+ // Text-input placeholder (only for elements that support inner text)
266+ if ([wrappedSnapshot fb_supportsPlaceholder ]) {
267+ blocks[FBExclusionAttributePlaceholderValue] = ^{
268+ return (NSString *)FBValueOrNull (wrappedSnapshot.wdPlaceholderValue );
269+ };
270+ }
271+
272+ return blocks;
273+ }
274+
275275+ (NSDictionary *)accessibilityInfoForElement : (id <FBXCElementSnapshot>)snapshot
276276{
277277 FBXCElementSnapshotWrapper *wrappedSnapshot = [FBXCElementSnapshotWrapper ensureWrapped: snapshot];
0 commit comments