appium: iOS TextField `clear` not working on iOS 12.x with Xcode 11

The problem

I have updated my environment with Xcode 11 and Appium 1.15.0. The clear function on iOS TextField still works fine on iOS 13.0, but not anymore on 12.x

Environment

  • Appium version (or git revision) that exhibits the issue: 1.15.0
  • Last Appium version that did not exhibit the issue (if applicable): 1.14.2
  • Desktop OS/version used to run Appium: macOS 10.14.6 with Xcode 11
  • Node.js version (unless using Appium.app|exe): 11.9.0
  • Npm or Yarn package manager: 6.9.0
  • Mobile platform/version under test: iOS 12.2, 13.0
  • Real device or emulator/simulator: Simulator and actual devices
  • Appium CLI or Appium.app|exe: CLI

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 29 (9 by maintainers)

Most upvoted comments

😃 I think it’s related with XCode 11’s update. As an example, getText() only works properly for iOS 13, but not lower versions. (E.g. I have a TextField which returns the placeholder all the time, although the value attribute is properly set in the PageSource 😉 😃)

XCode 11 seems to be breaking a lot of stuff 😕

I’ve installed their latest XCode 11.1 GM Seed, still doesn’t fix it …

One of the things I’ve noticed is that my PageSource now contains a lot of XCUIElementTypeOther… Something like this:

<TextInput
  accessible={true}
  accessibilityLabel="BeveilingingscodeTextBox"
  autoCorrect={false}
  placeholder="Vul hier de 8 cijferige code in"
  returnKeyType="done"
  spellCheck={false}
  style={styles.formElementInput}
  keyboardType="number-pad"
  maxLength={this.state.maxLength}
  onChangeText={this.handleResponseCode}
  value={this.state.responseCode}
/>

Is generating:

<XCUIElementTypeOther type="XCUIElementTypeOther" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="true" x="40" y="267" width="295" height="29">
  <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="12345671" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="true" x="40" y="267" width="295" height="28"/>
</XCUIElementTypeOther>

So, I was forced to do something like this to select the proper element:

  const fields = await $$(`~${fieldLabel}`);
  const tags = await Promise.all(fields.map((f) => f.getTagName()));
  const field = fields.filter((f, index) => tags[index] !== 'XCUIElementTypeOther').pop();

On iOS >= 13.0

  • Tests pass.

On iOS < 13.0

  • Downgrading Appium’s version does not help.
  • field.clearValue() does not work
  • field.setValue() works
  • field.getText() / field.getValue() return the placeholder’s value…
  • If I remove the placeholder attribute it returns the label’s value…
  • If I change the placeholder value to {this.state.responseCode} then all tests pass, because it retrieves the right value (… doesn’t look like something I’d like to ship though 😄 )

ah, forgot to update the page. https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/wda-custom-server.md is updated. The path has been node_modules/appium/node_modules/appium-webdriveragent.

There is no magic there - WDA simply tries to enter enough delete/backspace chars into the text field to make its content disappear. This might not work properly if XcTest does not properly return the actual value or if it fails to send the actual keys. In any case there is nothing one can do from Appium side. As a workaround you could try to perform long tap in the text field and do Select All->Delete or double tap to select the text and then press Delete. Or report the issue to Apple, which I don’t think they would care much %)

thanks so much. It means we cannot get the value even if we use vanilla XCUITest

The verified solution for clearing the text in IOS Simulator or device MobileElement element = driver.findElement(By.id(“id_data”)); Rectangle rectangle = element.getRect(); int YAxis = element.getCenter().getY(); int XAxis = rectangle.getWidth(); TouchAction action = new TouchAction(this.getIOSDriver()); action.tap(TapOptions.tapOptions().withPosition(PointOption.point(XAxis, YAxis))).perform(); element.clear();

Verified on Simulator iOS 14.3 with appium 1.21.0

Thanks 👀

I hope… but I have no exact answer, sorry. we should know more about the API. A known issue for it is visibility attribute. We addressed shouldUseTestManagerForVisibilityDetection in includeNonModalElements’s description.

Don’t know exactly how to interpret these differences, but

With includeNonModalElements as false:

<XCUIElementTypeOther type="XCUIElementTypeOther" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="true" x="40" y="267" width="295" height="29">
  <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="12345671" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="true" x="40" y="267" width="295" height="28"/>
</XCUIElementTypeOther>

With includeNonModalElements as true:

<XCUIElementTypeOther type="XCUIElementTypeOther" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="false" x="40" y="267" width="295" height="29">
  <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="Vul hier de 8 cijferige code in" name="BeveilingingscodeTextBox" label="BeveilingingscodeTextBox" enabled="true" visible="false" x="40" y="267" width="295" height="28"/>
</XCUIElementTypeOther>

Apparently if I set it to true it reflects what is returned in the getText() ?

There is no magic there - WDA simply tries to enter enough delete/backspace chars into the text field to make its content disappear. This might not work properly if XcTest does not properly return the actual value or if it fails to send the actual keys. In any case there is nothing one can do from Appium side. As a workaround you could try to perform long tap in the text field and do Select All->Delete or double tap to select the text and then press Delete. Or report the issue to Apple, which I don’t think they would care much %)

So, I’m guessing this is happening due to the issue I have found: https://github.com/appium/appium/issues/13289 I actually had to go with long tap > select all > backspace delete manually.

Just to confirm, I ran on Xcode 11, on iPhone SE simulator with iOS 12.2, latest Appium 1.15.0 release.