[Flutter] I can't get iOS element.clear() to work - Appium 2.5.1

Hi everyone, I am using Appium version 2.5.1 with behave and python, and I am experiencing issues with clear() on iOS. It doesn’t clear input field text.
What I’ve tried.

element.clear() - obviously doesn’t work

Tried to loop and delete with

element.send_keys(‘\ue003’) - only deletes one letter

element.send_keys(Keys.SHIFT, Keys.HOME)

My code:

@when(u'User enters email')
def step_impl(context):
    login_page.input_email().send_keys('[email protected]')

My logs when attempting clear() function

[XCUITestDriver@cac0 (059a240d)] Calling AppiumDriver.clear() with args: [“23000000-0000-0000-5D2C-000000000000”,“059a240d-6dc8-421a-b9d9-cf0670b04217”]
[XCUITestDriver@cac0 (059a240d)] Executing command ‘clear’
[XCUITestDriver@cac0 (059a240d)] Matched ‘/element/23000000-0000-0000-5D2C-000000000000/clear’ to command name ‘clear’
[XCUITestDriver@cac0 (059a240d)] Proxying [POST /element/23000000-0000-0000-5D2C-000000000000/clear] to [POST] with no body
[XCUITestDriver@cac0 (059a240d)] Got response with status 200: {“value”:null,“sessionId”:“026D9940-1045-4011-B61C-570F4391E5F8”}
[XCUITestDriver@cac0 (059a240d)] Responding to client with driver.clear() result: null

Unit test passed. Do you want to look at the test code to see if it helps?

1 Like

I am not sure how this may help me, asserting text and getting attribute ‘value’, what’s the logic behind it?

I’m giving you the unit test for iOS element.clear(). It’s a pretty simple algorithm. Code is working.

You have not provided your code, nor any logs with errors, or anything else to support the position that:

I don’t know what is going wrong for you. However, I can point you to working code in the hopes that you get something out of it.

I will say it’s a bit disheartening that the code looks so foreign to you and you can’t see the logic. That unit test is a good example of how to use element.clear(). My best advice is to code your tests along similar lines.

1 Like

I met with such situation when input fields are on WEB page while app itself is native with iOS app.
I did not want switch context but just added logic here to delete input and check it value. There are many ways to do it

  • tap on input and tap delete key several times. check input. repeat 2-3 times
  • double tap → tap on appeared delete menu → repeat 2-3 times
    Some time later i found that clear input started work but for sure left it executed 2 times.

good luck

1 Like

Thank you for your response.
I’ve updated my code and included the logs.
The code is not foreign, I’ve investigated this issue a bit and I am trying to understand why clear() → results in null.

I am testing a Flutter App. Clear doesn’t work for both android and ios.
For Android I managed to loop and perform delete key action.
For iOS I’ve tried this but no luck:

# Tap on the input element

# Tap the delete key several times (adjust the count as needed)
delete_count = 5
for _ in range(delete_count):

Also I’ve tried


and also by replacing DELETE with clear() - 0 luck with this way.
Could you please provide an example?

When compared to unit test, there is an important step missing:

Do you see how the element needs to be found again to update the value? There is even a comment on this. Without finding element again, probably looking at a stale reference. Need to update so that element.clear() has something to operate on.

Can you try finding element again before performing element.clear() operation on it?

1 Like

1 After tap on input keyboard appears ?
2 You know that you can tap on any keyboard key as far as it is visible on iOS (unlike Android) ? So you can find Delete key just as element on screen and tap on it.

1 Like
  1. Tap on input doesn’t activate keyboard, send_keys does
  2. Thank you very much for this

I’ve managed to solve it like this:

    def clear_input_field_ios(context):
        delete = WebDriverWait(context.driver, 10).until(
            EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, 'delete'))
        delete_count = 40
        for _ in range(delete_count):

It’s ugly but it works, what I’m going to do next is get text value from input field, so that I get number of characters and loop on it.

I’ve lost lots of time unsuccessfully getting the text value

el = login_page.input_email()

—> returns EMAIL_LOGIN to my surprise [check appium inspector image]



(understandably) because those are the labels I’ve defined in my Flutter app.

I’ve tried also

text = element.get_attribute('innerText')
text = element.get_attribute('textContent')

with no success

If you have any idea of how to get text in this example, I would be really grateful, you guys certainly help me tremendously already!

These are the values from Appium inspector:

In iOS value you entered can apply into name, value or label attribute. With Appium inspector tap and fill manually this field and check with inspector where you see entered text.

1 Like

I’ve done it. No value is being updated no matter what keys I send.
No name, label or value attributes.

I presume this is because I have manually added Semantics widgets to my Flutter App to those input fields in order to use Accessibility IDs instead of XPATH.

Is there an alternative?

If you cant see entered text with Appium inspector or xCode Layout inspector → try ask on Flutter forum.

1 Like