Search code examples
iosappiumui-testingappium-ios

Testing iOS App on Simulator with Appium - Element Not Found


I'm using Appium client to record and generate the testing script for my iOS App. On the App Inspector, I can tap on a login button and generate the script (in python) like below:

els1 = driver.find_elements_by_accessibility_id("login")
els1[0].click()

I can successfully log in to my app tapping the button on the App Inspector yet I got an error as I run the script on mac terminal:

els3[0].click()

IndexError: list index out of range

I tried different ways to access the button element by using accessibility id, name and class name, but none of the above work.

What did I miss? Is it a bug of the Appium software?


Solution

  • After hours of googling and trying, I've found that the problem is about view refreshing.

    Every time a view transition or navigation happens, it takes time to update the view. Once everything is updated the webDriver could successfully identify an element using the given search parameters.

    So between every interaction just wait for a second:

    el1 = driver.find_element_by_accessibility_id("login")
    el1.click()
    // wait for the view to get updated
    driver.implicitly_wait(1)
    
    els2 = driver.find_elements_by_name("Edit")
    els2[0].click()
    

    And the script would run as expected.