Unable to detect textfield with placeholder text on Appium 1.20.x and iOS13+

Hi team, I’m having an issue finding a textfield element (with placeholder text) on Appium 1.20.x on iOS13+. This was working fine on Appium 1.19.x.

The UI test we’re doing is pretty straightforward:
1. Tap on a textfield element, identified by the string value of the placeholder
2. Enter some value into the textfield

Our dev environment:
* Appium 1.20.x
* Appium-Python-Client 0.48
* behave 1.2.6
* python 3.8.1
* selenium 3.141

iOS currently does not have an accessibility identifier assigned to the textfield, since we’ve been able to find the placeholder text of the textfield without issue on 1.19.x. I’ve provided a screenshot of the iOS screen with the textfield element.

Sample code of what we’re trying to do:

    from appium.webdriver.common.mobileby import MobileBy
    from appium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    # Capabilities for local run
    capabilities = { ... }
    driver =  webdriver.Remote("http://localhost:4723/wd/hub", capabilities)
    # Wait for element for up to 5 seconds
    wait = WebDriverWait(driver, 5)
    # Find text field with a placeholder text "Enter our email address"
    locator = (MobileBy.ACCESSIBILITY_ID, 'Enter your email address')

    # Times out here on Appium 1.20.x but works fine on 1.19.x
    element = wait.until(EC.presence_of_element_located(locator)) 

Did Appium 1.20.x change the way elements are found on screen? If so, what do I need to change/add in order to find the element again using the previous pattern with MobileBy.ACCESSIBILITY_ID?

Exception from Appium logs.

[debug] [W3C (61fb666a)] Calling AppiumDriver.findElement() with args: ["accessibility id","Enter your email address","61fb666a-36ca-4063-925c-7c2aef115175"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id, css selector
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST] with body: {"using":"accessibility id","value":"Enter your email address"}
[WD Proxy] Got response with status 404: {"value":{"error":"no such element","message":"unable to find an element using 'accessibility id', value 'Enter your email address'","traceback":"(\n\t0   WebDriverAgentLib                   0x0000000105f0c74a FBNoSuchElementErrorResponseForRequest + 298\n\t1   WebDriverAgentLib                   0x0000000105f0c509 +[FBFindElementCommands handleFindElement:] + 409\n\t2   WebDriverAgentLib                   0x0000000105ec7ab6 -[FBRoute_TargetAction mountRequest:intoResponse:] + 182\n\t3   WebDriverAgentLib                   0x0000000105ea1938 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 536\n\t4   WebDriverAgentLib                   0x0000000105eee8eb -[RoutingHTTPServer handleRoute:withRequest:response:] + 219\n\t5   WebDriverAgentLib                   0x0000000105eef7e3 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 83\n\t6   libdispatch.dylib                   0x00007fff519798cb _dispatch_client_callout + 8\n\t7   libdispatch.dylib                 ...
[debug] [W3C] Matched W3C error code 'no such element' to NoSuchElementError
[debug] [W3C (61fb666a)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [W3C (61fb666a)]     at XCUITestDriver.doNativeFind (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/find.js:130:11)
[debug] [W3C (61fb666a)]     at process._tickCallback (internal/process/next_tick.js:68:7)
[HTTP] <-- POST /wd/hub/session/61fb666a-36ca-4063-925c-7c2aef115175/element 404 33 ms - 446
1 Like

locator = (MobileBy.ACCESSIBILITY_ID, ‘Enter your email address’)

as I understand, ACCESSIBILITY_ID is used when it is detected and shown in Appium Desktop. Otherwise, the element isnt found.

I think you can try to use -ios classchain or className

List textfield_elements = driver.findElements(MobileBy.className(“XCUIElementTypeTextField”));

Thanks Lien for the quick response! The same locator and declaration works as expected on 1.19.x. We’re puzzled why it just stopped working on 1.20.x.

We can try className, although there are multiple elements of class XCUIElementTypeTextField on this and other screens, which means we’ll have to include more filtering. We also use the same declarations on Android, so XCUIElementTypeTextField will not work for multi-platform support.

I’m wondering if there’s something in the capability that we may have missed that allows us to use the same declarations on Appium 1.20.x as 1.19.x?

Use predicate locator instead: value == 'Enter your email address'

1 Like

Thank you. Looks like we can use this as a workaround for now!