Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to append text due to placeholder value being returned as element value #986

Open
luckyyyyy opened this issue Mar 7, 2025 · 9 comments

Comments

@luckyyyyy
Copy link

Description

I'm trying to implement a text append functionality for text fields in my automation tests, but I've noticed that the current implementation in XCUIElement+FBWebDriverAttributes.m prevents this from working correctly.

In the wdValue method, when handling text fields, the code sets the placeholder value as a fallback when the actual value is empty:

else if (elementType == XCUIElementTypeTextView ||
         elementType == XCUIElementTypeTextField ||
         elementType == XCUIElementTypeSecureTextField) {
  NSString *placeholderValue = self.placeholderValue;
  value = FBFirstNonEmptyValue(value, placeholderValue);
}

This causes an issue where I can never properly append text to a field that has a placeholder, as the WebDriverAgent returns the placeholder text instead of an empty string when the field is empty.

Question

  1. Why was the decision made to return the placeholder value as the element's value? I understand this might be useful for element location/identification, but it breaks the ability to append text.
  2. Is there another way to implement text append functionality while maintaining this behavior?
  3. Would it be possible to add an additional attribute that returns the raw value without the placeholder fallback?

Reference

https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Categories/XCUIElement%2BFBWebDriverAttributes.m#L84

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 8, 2025

Why was the decision made to return the placeholder value as the element's value? I understand this might be useful for element location/identification, but it breaks the ability to append text.

As Appium, this is because the original project already implemented so. This project keeps the backward compatibility.

Would it be possible to add an additional attribute that returns the raw value without the placeholder fallback?
Would it be possible to add an additional attribute that returns the raw value without the placeholder fallback?

would #987 help?

@luckyyyyy
Copy link
Author

Why was the decision made to return the placeholder value as the element's value? I understand this might be useful for element location/identification, but it breaks the ability to append text.

As Appium, this is because the original project already implemented so. This project keeps the backward compatibility.

Would it be possible to add an additional attribute that returns the raw value without the placeholder fallback?
Would it be possible to add an additional attribute that returns the raw value without the placeholder fallback?

would #987 help?

thank, I've considered adding a placeholderValue, but that would create another issue - I actually can't tell when the value is empty, because if the value matches the placeholderValue, that would be disastrous.

@KazuCocoa
Copy link
Member

Ah, without placeholder.
Probably then we need to add a new property name which doesn't have the placeholder one

@luckyyyyy
Copy link
Author

Ah, without placeholder. Probably then we need to add a new property name which doesn't have the placeholder one

Yes, I think we need a new name to represent the original value

@KazuCocoa
Copy link
Member

Or would “label” help? It comes from accessibilityLabel. So if OS didn't assign your placeholder value as the label value, it might help

@luckyyyyy
Copy link
Author

No way, I tried all attributes, and finally found in the source code that it uses placeholderValue. Since my automated testing is now AI-based and doesn't need to consider element lookup, I temporarily removed placeholderValue locally.

@KazuCocoa
Copy link
Member

Perhaps only id value = self.value; https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Categories/XCUIElement%2BFBWebDriverAttributes.m#L69 attribute could be added. We need to define the attribute name though.

@luckyyyyy
Copy link
Author

Yes, I think the only solution is to add a new attribute, such as original value.

@KazuCocoa
Copy link
Member

Do you need like https://github.com/appium/WebDriverAgent/compare/master...appium:WebDriverAgent:xcvalue?expand=1 or placeholderValue would be sufficient to check the element condition?

e.g.

<XCUIElementTypeTextField type="XCUIElementTypeTextField" value="Placeholder text" xcValue="Placeholder text" label="" enabled="true" visible="false" accessible="true" x="86" y="528" width="221" height="30" index="4" placeholderValue="Placeholder text">

<XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" value="••••" xcValue="••••" label="" enabled="true" visible="true" accessible="true" x="86" y="342" width="221" height="35" index="4" placeholderValue="Placeholder text">
> e = driver.find_element :predicate, 'placeholderValue == "Placeholder text" AND value="••••"'
=> #<Appium::Core::Element:0x4262bd5cf740ac8e id="04000000-0000-0000-342C-010000000000">
> e.value
=> "••••"
[130] pry(main)> e.placeholderValue
=> "Placeholder text"

When I tested that with our testing app:

Image

value by XCTest also had the placeholder value as value. So, all placeholder included elements had the placeholder value as value.

Could you share your target page source with https://github.com/appium/WebDriverAgent/compare/master...appium:WebDriverAgent:xcvalue?expand=1 branch to see the actual page source? I'd like to check value by XCTest (xcValue in this branch's case), placeholderValue and value by WDA patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants