Skip to content

Commit 4f9415a

Browse files
feat: add placeholderValue to /source for text input elements only
1 parent 824dac0 commit 4f9415a

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
202202
info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel);
203203
info[@"rect"] = wrappedSnapshot.wdRect;
204204

205-
NSDictionary<NSString *, NSString * (^)(void)> *attributeBlocks = @{
205+
// Define the base attribute blocks that apply to all elements.
206+
NSDictionary<NSString *, NSString * (^)(void)> *baseAttributeBlocks = @{
206207
FBExclusionAttributeFrame: ^{
207208
return NSStringFromCGRect(wrappedSnapshot.wdFrame);
208209
},
@@ -217,11 +218,28 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
217218
},
218219
FBExclusionAttributeFocused: ^{
219220
return [@([wrappedSnapshot isWDFocused]) stringValue];
220-
},
221-
FBExclusionAttributePlaceholderValue: ^{
222-
return FBValueOrNull(wrappedSnapshot.wdPlaceholderValue);
223221
}
224222
};
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+
}
225243

226244
NSSet *nonPrefixedKeys = [NSSet setWithObjects:FBExclusionAttributeFrame, FBExclusionAttributePlaceholderValue, nil];
227245

0 commit comments

Comments
 (0)