Search code examples
appiumrobotframeworkappium-androidselenium2library

Couldn't able to use Xpath in Appium + Robot Framework where in Appium Log its displaying error message as contextId: ' multiple: true'


Using Robot Framework with combination of Appium and Selenium2Library/SeleniumLibrary. If I tried to run my script with some xpath locators like as below

 AppiumLibrary.Click Element                       xpath=//android.widget.TextView[@text='Site Control'] 

in keywords file then getting below the error message.

Error Message:

Finding '//android.widget.EditText[@index='4']' using 'XPATH' with the contextId: '' multiple: true

Appium Logs:

 [debug] [35m[AndroidBootstrap][39m [BOOTSTRAP LOG] [debug] Got command of type ACTION
 [debug] [35m[AndroidBootstrap][39m [BOOTSTRAP LOG] [debug] Got command action: find
 [debug] [35m[AndroidBootstrap][39m [BOOTSTRAP LOG] [debug] Finding '//android.widget.EditText[@index='4']' using 'XPATH' with the contextId: '' multiple: true

Robot Script:

 Click on Site Control and Create Case
      AppiumLibrary.Click Element                       xpath=//android.widget.TextView[@text='Site Control']
      sleep                                             ${timeout}
      AppiumLibrary.click element                       xpath=//android.widget.EditText[@index='4']
      sleep                                             ${timeout}
      AppiumLibrary.input text                          xpath=//android.widget.EditText[@text='Intallationid']   site212

Solution

  • Finally, found an answer for this error message. Issue is Development team are maintaining common variable names for UI elements in their React Native code to reuse it and to overcome from this error is adding the UiAutomator2 capabilities like below:

    For Java with Appium (Appium Java Client)

    capabilities.setCapability("automationName", "UiAutomator2");
    

    For Robot Framework (robot AppiumLibrary)

    automationName=UiAutomator2 (inside open application keyword)
    

    Why this error was coming? Appium isn't supporting UiAutomator automation if our device/emulator OS version is >= 6. I was using 7+. So, I have switch to UiAutomator2 and Make sure JAVA_HOME & ANDROID_HOME is set properly.